private void SubtractItemToInventory(long SOID) { SODetails clsSODetails = Details(SOID); ERPConfig clsERPConfig = new ERPConfig(base.Connection, base.Transaction); ERPConfigDetails clsERPConfigDetails = clsERPConfig.Details(); SOItem clsSOItem = new SOItem(base.Connection, base.Transaction); ProductUnit clsProductUnit = new ProductUnit(base.Connection, base.Transaction); Products clsProduct = new Products(base.Connection, base.Transaction); ProductVariationsMatrix clsProductVariationsMatrix = new ProductVariationsMatrix(base.Connection, base.Transaction); ProductPackage clsProductPackage = new ProductPackage(base.Connection, base.Transaction); MatrixPackage clsMatrixPackage = new MatrixPackage(base.Connection, base.Transaction); Inventory clsInventory = new Inventory(base.Connection, base.Transaction); InventoryDetails clsInventoryDetails; //MatrixPackagePriceHistoryDetails clsMatrixPackagePriceHistoryDetails; //ProductPackagePriceHistoryDetails clsProductPackagePriceHistoryDetails; System.Data.DataTable dt = clsSOItem.ListAsDataTable(SOID, "SOItemID", SortOption.Ascending); foreach (System.Data.DataRow dr in dt.Rows) { long lngProductID = long.Parse(dr["ProductID"].ToString()); int intProductUnitID = int.Parse(dr["ProductUnitID"].ToString()); decimal decItemQuantity = decimal.Parse(dr["Quantity"].ToString()); decimal decQuantity = clsProductUnit.GetBaseUnitValue(lngProductID, intProductUnitID, decItemQuantity); long lngVariationMatrixID = long.Parse(dr["VariationMatrixID"].ToString()); string strMatrixDescription = "" + dr["MatrixDescription"].ToString(); string strProductCode = "" + dr["ProductCode"].ToString(); decimal decUnitCost = decimal.Parse(dr["UnitCost"].ToString()); decimal decItemCost = decimal.Parse(dr["Amount"].ToString()); decimal decVAT = decimal.Parse(dr["VAT"].ToString()); ///******************************************* // * Add in the Sales Price History // * ****************************************/ //if (lngVariationMatrixID != 0) //{ // // Update MatrixPackagePriceHistory first to get the history // clsMatrixPackagePriceHistoryDetails = new MatrixPackagePriceHistoryDetails(); // clsMatrixPackagePriceHistoryDetails.UID = clsSODetails.SellerID; // clsMatrixPackagePriceHistoryDetails.PackageID = clsMatrixPackage.GetPackageID(lngVariationMatrixID, intProductUnitID); // clsMatrixPackagePriceHistoryDetails.ChangeDate = DateTime.Now; // clsMatrixPackagePriceHistoryDetails.Price = decUnitCost; // clsMatrixPackagePriceHistoryDetails.PurchasePrice = -1; //-1 = nochange // clsMatrixPackagePriceHistoryDetails.VAT = -1; //-1 = nochange // clsMatrixPackagePriceHistoryDetails.EVAT = -1; //-1 = nochange // clsMatrixPackagePriceHistoryDetails.LocalTax = -1; //-1 = nochange // clsMatrixPackagePriceHistoryDetails.Remarks = "Based on SO #: " + clsSODetails.SONo; // MatrixPackagePriceHistory clsMatrixPackagePriceHistory = new MatrixPackagePriceHistory(base.Connection, base.Transaction); // clsMatrixPackagePriceHistory.Insert(clsMatrixPackagePriceHistoryDetails); //} //else //{ // // Update ProductPackagePriceHistory first to get the history // clsProductPackagePriceHistoryDetails = new ProductPackagePriceHistoryDetails(); // clsProductPackagePriceHistoryDetails.UID = clsSODetails.SellerID; // clsProductPackagePriceHistoryDetails.PackageID = clsProductPackage.GetPackageID(lngProductID, intProductUnitID); // clsProductPackagePriceHistoryDetails.ChangeDate = DateTime.Now; // clsProductPackagePriceHistoryDetails.Price = decUnitCost; // clsProductPackagePriceHistoryDetails.PurchasePrice = -1; //-1 = nochange // clsProductPackagePriceHistoryDetails.VAT = -1; //-1 = nochange // clsProductPackagePriceHistoryDetails.EVAT = -1; //-1 = nochange // clsProductPackagePriceHistoryDetails.LocalTax = -1; //-1 = nochange // clsProductPackagePriceHistoryDetails.Remarks = "Based on SO #: " + clsSODetails.SONo; // ProductPackagePriceHistory clsProductPackagePriceHistory = new ProductPackagePriceHistory(base.Connection, base.Transaction); // clsProductPackagePriceHistory.Insert(clsProductPackagePriceHistoryDetails); //} /******************************************* * Subtract to Inventory * ****************************************/ // clsProduct.SubtractQuantity(lngProductID, decQuantity); // if (lngVariationMatrixID != 0) { clsProductVariationsMatrix.SubtractQuantity(lngVariationMatrixID, decQuantity); } // July 28, 2011: change the above codes to the following clsProduct.SubtractQuantity(clsSODetails.BranchID, lngProductID, lngVariationMatrixID, decQuantity, Products.getPRODUCT_INVENTORY_MOVEMENT_VALUE(PRODUCT_INVENTORY_MOVEMENT.DEDUCT_SOLD_WHOLESALE), DateTime.Now, clsSODetails.SONo, clsSODetails.SellerName); /******************************************* * Update Selling Information * ****************************************/ int iBaseUnitID = clsProduct.get_BaseUnitID(lngProductID); if (iBaseUnitID != intProductUnitID) { clsProduct.UpdateSellingPrice(lngProductID, lngVariationMatrixID, clsSODetails.CustomerID, intProductUnitID, (decItemQuantity * decUnitCost) / decQuantity, -1, -1, -1,- 1, -1); // Price should be the sugegsted selling price } clsProduct.UpdateSellingWSPrice(lngProductID, lngVariationMatrixID, clsSODetails.CustomerID, intProductUnitID, decUnitCost); // WS Price should be the unit cost /******************************************* * Add to Inventory Analysis * ****************************************/ clsInventoryDetails = new InventoryDetails(); clsInventoryDetails.PostingDateFrom = clsERPConfigDetails.PostingDateFrom; clsInventoryDetails.PostingDateTo = clsERPConfigDetails.PostingDateTo; clsInventoryDetails.PostingDate = clsSODetails.DeliveryDate; clsInventoryDetails.ReferenceNo = clsSODetails.SONo; clsInventoryDetails.ContactID = clsSODetails.CustomerID; clsInventoryDetails.ContactCode = clsSODetails.CustomerCode; clsInventoryDetails.ProductID = lngProductID; clsInventoryDetails.ProductCode = strProductCode; clsInventoryDetails.VariationMatrixID = lngVariationMatrixID; clsInventoryDetails.MatrixDescription = strMatrixDescription; clsInventoryDetails.SoldQuantity = decQuantity; clsInventoryDetails.SoldCost = decItemCost - decVAT; clsInventoryDetails.SoldVAT = decItemCost; // Sales Cost with VAT clsInventory.Insert(clsInventoryDetails); } }
private void AddItemToInventory(long TransferInID) { try { TransferInDetails clsTransferInDetails = Details(TransferInID); ERPConfig clsERPConfig = new ERPConfig(base.Connection, base.Transaction); ERPConfigDetails clsERPConfigDetails = clsERPConfig.Details(); TransferInItem clsTransferInItem = new TransferInItem(base.Connection, base.Transaction); ProductUnit clsProductUnit = new ProductUnit(base.Connection, base.Transaction); Products clsProduct = new Products(base.Connection, base.Transaction); ProductPackage clsProductPackage = new ProductPackage(base.Connection, base.Transaction); Inventory clsInventory = new Inventory(base.Connection, base.Transaction); InventoryDetails clsInventoryDetails; ProductPackagePriceHistoryDetails clsProductPackagePriceHistoryDetails; System.Data.DataTable dt = clsTransferInItem.ListAsDataTable(TransferInID, "TransferInItemID", SortOption.Ascending); foreach(System.Data.DataRow dr in dt.Rows) { long lngProductID = long.Parse(dr["ProductID"].ToString()); int intProductUnitID = int.Parse(dr["ProductUnitID"].ToString()); decimal decItemQuantity = decimal.Parse(dr["Quantity"].ToString()); decimal decQuantity = new ProductUnit().GetBaseUnitValue(lngProductID, intProductUnitID, decItemQuantity); long lngVariationMatrixID = long.Parse(dr["VariationMatrixID"].ToString()); string strMatrixDescription = "" + dr["MatrixDescription"].ToString(); string strProductCode = "" + dr["ProductCode"].ToString(); decimal decUnitCost = decimal.Parse(dr["UnitCost"].ToString()); decimal decItemCost = decimal.Parse(dr["Amount"].ToString()); decimal decSellingPrice = Convert.ToDecimal(dr["SellingPrice"]); decimal decVAT = Convert.ToDecimal(dr["VAT"]); // myReader.GetDecimal("VAT"); decimal decEVAT = Convert.ToDecimal(dr["EVAT"]); decimal decLocalTax = Convert.ToDecimal(dr["LocalTax"]); /******************************************* * Add in the Price History * ****************************************/ // Update ProductPackagePriceHistory first to get the history clsProductPackagePriceHistoryDetails = new ProductPackagePriceHistoryDetails(); clsProductPackagePriceHistoryDetails.UID = clsTransferInDetails.TransferrerID; clsProductPackagePriceHistoryDetails.PackageID = new ProductPackage().GetPackageID(lngProductID, intProductUnitID); clsProductPackagePriceHistoryDetails.ChangeDate = DateTime.Now; clsProductPackagePriceHistoryDetails.PurchasePrice = (decItemQuantity * decUnitCost) / decQuantity; clsProductPackagePriceHistoryDetails.Price = decSellingPrice; clsProductPackagePriceHistoryDetails.VAT = decVAT; clsProductPackagePriceHistoryDetails.EVAT = decEVAT; clsProductPackagePriceHistoryDetails.LocalTax = decLocalTax; clsProductPackagePriceHistoryDetails.Remarks = "Based on TransferIn #: " + clsTransferInDetails.TransferInNo; ProductPackagePriceHistory clsProductPackagePriceHistory = new ProductPackagePriceHistory(base.Connection, base.Transaction); clsProductPackagePriceHistory.Insert(clsProductPackagePriceHistoryDetails); /******************************************* * Add to Inventory * ****************************************/ //clsProduct.AddQuantity(lngProductID, decQuantity); //if (lngVariationMatrixID != 0) //{ // clsProductVariationsMatrix.AddQuantity(lngVariationMatrixID, decQuantity); //} // July 26, 2011: change the above codes to the following clsProduct.AddQuantity(clsTransferInDetails.BranchID, lngProductID, lngVariationMatrixID, decQuantity, Products.getPRODUCT_INVENTORY_MOVEMENT_VALUE(PRODUCT_INVENTORY_MOVEMENT.ADD_TRANSFER_IN), DateTime.Now, clsTransferInDetails.TransferInNo, clsTransferInDetails.TransferrerName); /******************************************* * Update Purchasing Information * ****************************************/ int iBaseUnitID = clsProduct.get_BaseUnitID(lngProductID); if (iBaseUnitID != intProductUnitID) { clsProduct.UpdatePurchasing(lngProductID, lngVariationMatrixID, clsTransferInDetails.SupplierID, iBaseUnitID, (decItemQuantity * decUnitCost) / decQuantity); } clsProduct.UpdatePurchasing(lngProductID, lngVariationMatrixID, clsTransferInDetails.SupplierID, intProductUnitID, decUnitCost); /******************************************* * Add to Inventory Analysis * ****************************************/ clsInventoryDetails = new InventoryDetails(); clsInventoryDetails.PostingDateFrom = clsERPConfigDetails.PostingDateFrom; clsInventoryDetails.PostingDateTo = clsERPConfigDetails.PostingDateTo; clsInventoryDetails.PostingDate = clsTransferInDetails.DeliveryDate; clsInventoryDetails.ReferenceNo = clsTransferInDetails.TransferInNo; clsInventoryDetails.ContactID = clsTransferInDetails.SupplierID; clsInventoryDetails.ContactCode = clsTransferInDetails.SupplierCode; clsInventoryDetails.ProductID = lngProductID; clsInventoryDetails.ProductCode = strProductCode; clsInventoryDetails.VariationMatrixID = lngVariationMatrixID; clsInventoryDetails.MatrixDescription = strMatrixDescription; clsInventoryDetails.TransferInQuantity = decQuantity; clsInventoryDetails.TransferInCost = decItemCost - decVAT; clsInventoryDetails.TransferInVAT = decItemCost; // TransferIn Cost with VAT clsInventory.Insert(clsInventoryDetails); /******************************************* * Added April 28, 2010 4:20PM * Update Selling Information when TransferIn is posted * ****************************************/ clsProduct.UpdateSellingPrice(lngProductID, lngVariationMatrixID, clsTransferInDetails.SupplierID, intProductUnitID, decimal.Parse(dr["SellingPrice"].ToString()), -1, -1, -1, -1, -1); //if (lngVariationMatrixID != 0) //{ // clsProductVariationsMatrix.UpdateSellingWithSameQuantityAndUnit(lngVariationMatrixID, clsPODetails.SupplierID, intProductUnitID, decimal.Parse(myReader["SellingPrice"); //} /******************************************* * Added April 28, 2010 4:20PM * Update the purchase price history to check who has the lowest price. * ****************************************/ ProductPurchasePriceHistoryDetails clsProductPurchasePriceHistoryDetails = new ProductPurchasePriceHistoryDetails(); clsProductPurchasePriceHistoryDetails.ProductID = lngProductID; clsProductPurchasePriceHistoryDetails.MatrixID = lngVariationMatrixID; clsProductPurchasePriceHistoryDetails.SupplierID = clsTransferInDetails.SupplierID; clsProductPurchasePriceHistoryDetails.PurchasePrice = decUnitCost; clsProductPurchasePriceHistoryDetails.PurchaseDate = clsTransferInDetails.TransferInDate; clsProductPurchasePriceHistoryDetails.Remarks = clsTransferInDetails.TransferInNo; ProductPurchasePriceHistory clsProductPurchasePriceHistory = new ProductPurchasePriceHistory(base.Connection, base.Transaction); clsProductPurchasePriceHistory.AddToList(clsProductPurchasePriceHistoryDetails); } } catch (Exception ex) { throw base.ThrowException(ex); } }
private void AddItemToInventory(long POID) { PODetails clsPODetails = Details(POID); ERPConfig clsERPConfig = new ERPConfig(base.Connection, base.Transaction); ERPConfigDetails clsERPConfigDetails = clsERPConfig.Details(); POItem clsPOItem = new POItem(base.Connection, base.Transaction); ProductUnit clsProductUnit = new ProductUnit(base.Connection, base.Transaction); Products clsProduct = new Products(base.Connection, base.Transaction); ProductVariationsMatrix clsProductVariationsMatrix = new ProductVariationsMatrix(base.Connection, base.Transaction); ProductPackage clsProductPackage = new ProductPackage(base.Connection, base.Transaction); Inventory clsInventory = new Inventory(base.Connection, base.Transaction); InventoryDetails clsInventoryDetails; ProductPackagePriceHistoryDetails clsProductPackagePriceHistoryDetails; //MySqlDataReader myReader = clsPOItem.List(POID, "POItemID", SortOption.Ascending); System.Data.DataTable dt = clsPOItem.ListAsDataTable(POID, "POItemID", SortOption.Ascending); //while (myReader.Read()) foreach (System.Data.DataRow dr in dt.Rows) { long lngProductID = Convert.ToInt64(dr["ProductID"]); int intProductUnitID = Convert.ToInt16(dr["ProductUnitID"]); decimal decItemQuantity = Convert.ToDecimal(dr["Quantity"]); decimal decQuantity = clsProductUnit.GetBaseUnitValue(lngProductID, intProductUnitID, decItemQuantity); long lngVariationMatrixID = Convert.ToInt64(dr["VariationMatrixID"]); string strMatrixDescription = dr["MatrixDescription"].ToString(); string strProductCode = dr["ProductCode"].ToString(); string strProductUnitCode = dr["ProductUnitCode"].ToString(); decimal decUnitCost = Convert.ToDecimal(dr["UnitCost"]); decimal decItemCost = Convert.ToDecimal(dr["Amount"]); decimal decSellingPrice = Convert.ToDecimal(dr["SellingPrice"]); decimal decVAT = Convert.ToDecimal(dr["VAT"]); decimal decEVAT = Convert.ToDecimal(dr["EVAT"]); decimal decLocalTax = Convert.ToDecimal(dr["LocalTax"]); /******************************************* * Add in the Price History * ****************************************/ // Update ProductPackagePriceHistory first to get the history clsProductPackagePriceHistoryDetails = new ProductPackagePriceHistoryDetails(); clsProductPackagePriceHistoryDetails.UID = clsPODetails.PurchaserID; clsProductPackagePriceHistoryDetails.PackageID = clsProductPackage.GetPackageID(lngProductID, intProductUnitID); clsProductPackagePriceHistoryDetails.ChangeDate = DateTime.Now; clsProductPackagePriceHistoryDetails.PurchasePrice = (decItemQuantity * decUnitCost) / decQuantity; clsProductPackagePriceHistoryDetails.Price = decSellingPrice; clsProductPackagePriceHistoryDetails.VAT = decVAT; clsProductPackagePriceHistoryDetails.EVAT = decEVAT; clsProductPackagePriceHistoryDetails.LocalTax = decLocalTax; clsProductPackagePriceHistoryDetails.Remarks = "Based on PO #: " + clsPODetails.PONo; ProductPackagePriceHistory clsProductPackagePriceHistory = new ProductPackagePriceHistory(base.Connection, base.Transaction); clsProductPackagePriceHistory.Insert(clsProductPackagePriceHistoryDetails); /******************************************* * Add to Inventory * ****************************************/ //clsProduct.AddQuantity(lngProductID, decQuantity); //if (lngVariationMatrixID != 0) { clsProductVariationsMatrix.AddQuantity(lngVariationMatrixID, decQuantity); } // July 26, 2011: change the above codes to the following clsProduct.AddQuantity(clsPODetails.BranchID, lngProductID, lngVariationMatrixID, decQuantity, Products.getPRODUCT_INVENTORY_MOVEMENT_VALUE(PRODUCT_INVENTORY_MOVEMENT.ADD_PURCHASE) + " @ " + decUnitCost.ToString("#,##0.#0") + "/" + strProductUnitCode, DateTime.Now, clsPODetails.PONo, clsPODetails.PurchaserName); /******************************************* * Update Purchasing Information * * 30May2013 Include variation in the package. * ****************************************/ int iBaseUnitID = clsProduct.get_BaseUnitID(lngProductID); if (iBaseUnitID != intProductUnitID) { clsProduct.UpdatePurchasing(lngProductID, lngVariationMatrixID, clsPODetails.SupplierID, iBaseUnitID, (decItemQuantity * decUnitCost) / decQuantity); } clsProduct.UpdatePurchasing(lngProductID, lngVariationMatrixID, clsPODetails.SupplierID, intProductUnitID, decUnitCost); /******************************************* * Add to Inventory Analysis * ****************************************/ clsInventoryDetails = new InventoryDetails(); clsInventoryDetails.BranchID = clsPODetails.BranchID; clsInventoryDetails.PostingDateFrom = clsERPConfigDetails.PostingDateFrom; clsInventoryDetails.PostingDateTo = clsERPConfigDetails.PostingDateTo; clsInventoryDetails.PostingDate = clsPODetails.DeliveryDate; clsInventoryDetails.ReferenceNo = clsPODetails.PONo; clsInventoryDetails.ContactID = clsPODetails.SupplierID; clsInventoryDetails.ContactCode = clsPODetails.SupplierCode; clsInventoryDetails.ProductID = lngProductID; clsInventoryDetails.ProductCode = strProductCode; clsInventoryDetails.VariationMatrixID = lngVariationMatrixID; clsInventoryDetails.MatrixDescription = strMatrixDescription; clsInventoryDetails.PurchaseQuantity = decQuantity; clsInventoryDetails.PurchaseCost = decItemCost - decVAT; clsInventoryDetails.PurchaseVAT = decItemCost; // Purchase Cost with VAT clsInventory.Insert(clsInventoryDetails); /******************************************* * Added Jan 1, 2010 4:20PM * Update Selling Information when PO is posted * ****************************************/ clsProduct.UpdateSellingPrice(lngProductID, lngVariationMatrixID, clsPODetails.SupplierID, intProductUnitID, Convert.ToDecimal(dr["SellingPrice"]), -1, -1, -1, -1, -1); /******************************************* * Added Mar 8, 2010 4:20PM * Update the purchase price history to check who has the lowest price. * ****************************************/ ProductPurchasePriceHistoryDetails clsProductPurchasePriceHistoryDetails = new ProductPurchasePriceHistoryDetails(); clsProductPurchasePriceHistoryDetails.ProductID = lngProductID; clsProductPurchasePriceHistoryDetails.MatrixID = lngVariationMatrixID; clsProductPurchasePriceHistoryDetails.SupplierID = clsPODetails.SupplierID; clsProductPurchasePriceHistoryDetails.PurchasePrice = decUnitCost; clsProductPurchasePriceHistoryDetails.PurchaseDate = clsPODetails.PODate; clsProductPurchasePriceHistoryDetails.Remarks = clsPODetails.PONo; clsProductPurchasePriceHistoryDetails.PurchaserName = clsPODetails.PurchaserName; ProductPurchasePriceHistory clsProductPurchasePriceHistory = new ProductPurchasePriceHistory(base.Connection, base.Transaction); clsProductPurchasePriceHistory.AddToList(clsProductPurchasePriceHistoryDetails); } //myReader.Close(); }
private void SynchronizeFromBranch() { try { lblError.Text = string.Empty; Branch clsBranch = new Branch(); BranchDetails clsBranchDetails = clsBranch.Details(Convert.ToInt16(cboSynchronizeFromBranch.SelectedItem.Value.ToString())); clsBranch.CommitAndDispose(); if (IPAddress.IsOpen(clsBranchDetails.DBIP, int.Parse(clsBranchDetails.DBPort)) == false) { lblError.Text = "Sorry cannot connect to Branch '" + cboSynchronizeFromBranch.SelectedItem.Text + "'. Please check you connection to IP Address :" + clsBranchDetails.DBIP + ". <br /><br />"; lblError.Text += "HOW TO CHECK : <br /><br />"; lblError.Text += " 1. Open command prompt<br />"; lblError.Text += " 2. Type ping[space][IP Address]<br /><br />"; lblError.Text += "If the answer is 'Request timed out.' then contact system administrator.<br />"; lblError.Text += "Else if the answer is 'Reply...' Follow the next steps.<br /><br />"; lblError.Text += " 3. Type telnet[space][IP Address][sapce][IP Port]<br /><br />"; return; } Session.Timeout = 60 * 60 * 30; Products clsProduct = new Products(); clsProduct.GetConnection(); ProductDetails clsProductDetails; ContactGroups clsContactGroup = new ContactGroups(clsProduct.Connection, clsProduct.Transaction); Contacts clsContact = new Contacts(clsProduct.Connection, clsProduct.Transaction); Data.Unit clsUnit = new Data.Unit(clsProduct.Connection, clsProduct.Transaction); Data.ProductGroup clsProductGroup = new Data.ProductGroup(clsProduct.Connection, clsProduct.Transaction); Data.ProductSubGroup clsProductSubGroup = new Data.ProductSubGroup(clsProduct.Connection, clsProduct.Transaction); Data.Variation clsVariation = new Variation(clsProduct.Connection, clsProduct.Transaction); RemoteBranchInventory clsBranchInventory = new RemoteBranchInventory(); clsBranchInventory.GetConnectionToBranch(clsBranchDetails.DBIP, clsBranchDetails.DBPort); Products clsBranchProduct = new Products(clsBranchInventory.Connection, clsBranchInventory.Transaction); ProductDetails[] arrBranchProductDetails = clsBranchProduct.List(); ContactGroups clsBranchContactGroup = new ContactGroups(clsBranchInventory.Connection, clsBranchInventory.Transaction); Contacts clsBranchContact = new Contacts(clsBranchInventory.Connection, clsBranchInventory.Transaction); Data.Unit clsBranchUnit = new Data.Unit(clsBranchInventory.Connection, clsBranchInventory.Transaction); Data.ProductGroup clsBranchProductGroup = new Data.ProductGroup(clsBranchInventory.Connection, clsBranchInventory.Transaction); Data.ProductSubGroup clsBranchProductSubGroup = new Data.ProductSubGroup(clsBranchInventory.Connection, clsBranchInventory.Transaction); Data.Variation clsBranchVariation = new Variation(clsBranchInventory.Connection, clsBranchInventory.Transaction); foreach (ProductDetails clsBranchProductDetails in arrBranchProductDetails) { clsProductDetails = clsBranchProductDetails; try { clsProductDetails.ProductID = clsProduct.Details(clsProductDetails.BarCode).ProductID; if (clsProductDetails.ProductID != 0) { lblError.Text += clsProductDetails.BarCode + " already exist.<br /><br />"; clsProduct.UpdatePurchasing(clsProductDetails.ProductID, clsBranchProductDetails.MatrixID, clsProductDetails.SupplierID, clsProductDetails.BaseUnitID, clsProductDetails.PurchasePrice); clsProduct.UpdateSellingPrice(clsProductDetails.ProductID, clsBranchProductDetails.MatrixID, clsProductDetails.SupplierID, clsProductDetails.BaseUnitID, clsProductDetails.Price, clsProductDetails.Price1, clsProductDetails.Price2, clsProductDetails.Price3, clsProductDetails.Price4, clsProductDetails.Price5); } else { clsProductDetails.ProductID = clsProduct.DetailsByCode(Constants.BRANCH_ID_MAIN, clsProductDetails.BarCode).ProductID; if (clsProductDetails.ProductID != 0) { lblError.Text += clsProductDetails.ProductCode + " already exist.<br /><br />"; clsProduct.UpdateBarcode(clsProductDetails.ProductID, clsProductDetails.BarCode); clsProduct.UpdatePurchasing(clsProductDetails.ProductID, clsBranchProductDetails.MatrixID, clsProductDetails.SupplierID, clsProductDetails.BaseUnitID, clsProductDetails.PurchasePrice); clsProduct.UpdateSellingPrice(clsProductDetails.ProductID, clsBranchProductDetails.MatrixID, clsProductDetails.SupplierID, clsProductDetails.BaseUnitID, clsProductDetails.Price, clsProductDetails.Price1, clsProductDetails.Price2, clsProductDetails.Price3, clsProductDetails.Price4, clsProductDetails.Price5); } else { clsProductDetails.SupplierID = clsContact.Details(clsProductDetails.SupplierCode).ContactID; if (clsProductDetails.SupplierID == 0) { ContactDetails clsBranchContactDetails = clsBranchContact.Details(clsProductDetails.SupplierCode); if (clsContactGroup.Details(clsBranchContactDetails.ContactGroupID).ContactGroupID == 0) { ContactGroupDetails clsBranchContactGroupDetails = clsBranchContactGroup.Details(clsBranchContactDetails.ContactGroupID); clsBranchContactDetails.ContactGroupID = clsContactGroup.Insert(clsBranchContactGroupDetails); } clsProductDetails.SupplierID = clsContact.Insert(clsBranchContactDetails); } clsProductDetails.BaseUnitID = clsUnit.Details(clsProductDetails.BaseUnitCode).UnitID; if (clsProductDetails.BaseUnitID == 0) { UnitDetails clsBranchUnitDetails = clsBranchUnit.Details(clsBranchProductDetails.BaseUnitID); clsProductDetails.BaseUnitID = clsUnit.Insert(clsBranchUnitDetails); } clsProductDetails.ProductGroupID = clsProductGroup.Details(clsProductDetails.ProductGroupCode).ProductGroupID; if (clsProductDetails.ProductGroupID == 0) { ProductGroupDetails clsBranchProductGroupDetails = clsBranchProductGroup.Details(clsBranchProductDetails.ProductGroupID); clsProductDetails.ProductGroupID = clsProductGroup.Insert(clsBranchProductGroupDetails); } clsProductDetails.ProductSubGroupID = clsProductSubGroup.Details(clsProductDetails.ProductSubGroupCode).ProductSubGroupID; if (clsProductDetails.ProductSubGroupID == 0) { ProductSubGroupDetails clsBranchProductSubGroupDetails = clsBranchProductSubGroup.Details(clsBranchProductDetails.ProductSubGroupID); clsProductDetails.ProductSubGroupID = clsProductSubGroup.Insert(clsBranchProductSubGroupDetails); } clsProductDetails.Quantity = 0; clsProductDetails.QuantityIN = 0; clsProductDetails.QuantityOUT = 0; try { clsProductDetails.ProductID = clsProduct.Insert(clsProductDetails); lblError.Text += clsProductDetails.ProductCode + " inserted.<br /><br />"; } catch (Exception exProduct){ lblError.Text += "<div class=ms-alternating> ERROR INSERTING ITEM: " + clsProductDetails.ProductCode + " err: " + exProduct.Message + ".</div><br /><br />"; if (clsProduct.Connection.State == ConnectionState.Closed) { clsProduct = new Products(); clsProduct.GetConnection(); clsContactGroup = new ContactGroups(clsProduct.Connection, clsProduct.Transaction); clsContact = new Contacts(clsProduct.Connection, clsProduct.Transaction); clsUnit = new Data.Unit(clsProduct.Connection, clsProduct.Transaction); clsProductGroup = new Data.ProductGroup(clsProduct.Connection, clsProduct.Transaction); clsProductSubGroup = new Data.ProductSubGroup(clsProduct.Connection, clsProduct.Transaction); clsVariation = new Variation(clsProduct.Connection, clsProduct.Transaction); } } } } } catch (Exception exProducts) { lblError.Text += "<div class=ms-alternating> ERROR INSERTING ITEM: " + clsProductDetails.ProductCode + " err: " + exProducts.Message + ".</div><br /><br />"; if (clsProduct.Connection.State == ConnectionState.Closed) { clsProduct = new Products(); clsProduct.GetConnection(); clsContactGroup = new ContactGroups(clsProduct.Connection, clsProduct.Transaction); clsContact = new Contacts(clsProduct.Connection, clsProduct.Transaction); clsUnit = new Data.Unit(clsProduct.Connection, clsProduct.Transaction); clsProductGroup = new Data.ProductGroup(clsProduct.Connection, clsProduct.Transaction); clsProductSubGroup = new Data.ProductSubGroup(clsProduct.Connection, clsProduct.Transaction); clsVariation = new Variation(clsProduct.Connection, clsProduct.Transaction); } } } clsProduct.CommitAndDispose(); clsBranchInventory.CommitAndDispose(); lblError.Text = "Done synchronizing products from Branch: " + clsBranchDetails.BranchCode + "<br /><br />" + lblError.Text; } catch (Exception ex) { lblError.Text += "ERROR WHILE CREATING INSERT STATEMENT: " + ex.Message; } }