private void btnSave_Click(object sender, EventArgs e) { var rec = new ReceiveDoc(); var itm = new Items(); //var itemprogram = new ProgramProduct(); string valid = ValidateFields(); if (valid == "true") { if ( XtraMessageBox.Show("Are you sure you want to save this transaction?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { try { for (int i = 0; i < dtRecGrid.Rows.Count; i++) { if (dtRecGrid.Rows[i]["Expiry Date"] != DBNull.Value) { if (Convert.ToDateTime(dtRecGrid.Rows[i]["Expiry Date"]) <= DateTime.Now) { var dialog = XtraMessageBox.Show( "The item " + dtRecGrid.Rows[i]["Item Name"].ToString() + " has already expired. Are you sure you want to receive it?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dialog == DialogResult.No) { return; } } } rec.AddNew(); rec.StoreID = Convert.ToInt32(cboStores.EditValue); rec.RefNo = txtRefNo.Text.Trim(); rec.Remark = txtRemark.Text; rec.ReceivedBy = txtReceivedBy.Text; DateTime xx = dtRecDate.Value; dtRecDate.CustomFormat = "MM/dd/yyyy"; DateTime dtRec = new DateTime(); rec.Date = ConvertDate.DateConverter(dtRecDate.Text); dtRec = ConvertDate.DateConverter(dtRecDate.Text); dtRecDate.IsGregorianCurrentCalendar = true; rec.EurDate = dtRecDate.Value; dtRecDate.IsGregorianCurrentCalendar = false; rec.ItemID = Convert.ToInt32(dtRecGrid.Rows[i][0]); switch (VisibilitySetting.HandleUnits) { case 1: rec.UnitID = 0; rec.QtyPerPack = Convert.ToInt32(dtRecGrid.Rows[i]["Qty/Pack"]); break; case 2: rec.UnitID = Convert.ToInt32(dtRecGrid.Rows[i]["UnitID"]); rec.QtyPerPack = 1; break; case 3: rec.UnitID = Convert.ToInt32(dtRecGrid.Rows[i]["UnitID"]); rec.QtyPerPack = 1; break; } rec.NoOfPack = Convert.ToInt32(dtRecGrid.Rows[i]["Pack Qty"]); rec.Quantity = rec.NoOfPack * rec.QtyPerPack; rec.QuantityLeft = rec.Quantity; if (dtRecGrid.Rows[i]["Price/Pack"] != null && dtRecGrid.Rows[i]["Price/Pack"].ToString() != "") { double pre = Convert.ToDouble(dtRecGrid.Rows[i]["Price/Pack"]) / rec.QtyPerPack; rec.Cost = Convert.ToDouble(pre); } else { rec.Cost = 0; } itm.LoadByPrimaryKey(Convert.ToInt32(dtRecGrid.Rows[i]["ID"])); rec.BatchNo = dtRecGrid.Rows[i][8].ToString(); if (dtRecGrid.Rows[i]["Expiry Date"] != DBNull.Value) { rec.ExpDate = Convert.ToDateTime(dtRecGrid.Rows[i]["Expiry Date"]); } if (dtRecGrid.Rows[i]["Internal Drug Code"] != DBNull.Value) { rec.InternalDrugCode = Convert.ToString(dtRecGrid.Rows[i]["Internal Drug Code"]); } rec.SupplierID = Convert.ToInt32(cboSupplier.EditValue); rec.SubProgramID = Convert.ToInt32(cboProgram.EditValue); ProgramProduct pr = new ProgramProduct(); pr.LoadByProgramProductByItemId(rec.ItemID, rec.StoreID); if (pr.RowCount == 0) { pr.AddNew(); pr.ItemID = rec.ItemID; pr.ProgramID = (rec.StoreID == 8)? 1000: 1001; pr.StoreID = rec.StoreID; pr.Save(); } string batch = DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + rec.ItemID.ToString(); rec.LocalBatchNo = batch; rec.Out = false; rec.IsApproved = false; dtRecDate.Value = xx; rec.Save(); //check if there is any data on stockoutLog about this item on this store //and update its enddate to today StockoutLog stockoutLog = new StockoutLog(); DataTable tblStockoutLog = stockoutLog.LoadByStoreAndItemId(rec.ItemID, rec.StoreID, true); if (tblStockoutLog != null) { if (tblStockoutLog.Rows.Count > 0) { stockoutLog.LoadByPrimaryKey(int.Parse(tblStockoutLog.Rows[0]["ID"].ToString())); stockoutLog.EndDate = DateTime.Today; stockoutLog.Save(); } } //itemprogram.LoadByOldProgramIdAndItemId(Convert.ToInt32(cboStores.EditValue), // Convert.ToInt32(dtRecGrid.Rows[i][0]), // Convert.ToInt32(cboProgram.EditValue)); //if (itemprogram.RowCount != 0) //{ // continue; //} //itemprogram.AddNew(); //itemprogram.StoreID = Convert.ToInt32(cboStores.EditValue); //itemprogram.ItemID = Convert.ToInt32(dtRecGrid.Rows[i][0]); //itemprogram.ProgramID = Convert.ToInt32(cboProgram.EditValue); //itemprogram.Save(); } XtraMessageBox.Show("Transaction Successfully Saved!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); ResetFields(); // mgr.CommitTransaction(); } catch (Exception exp) { //mgr.RollbackTransaction(); BLL.User user = new User(); user.LoadByPrimaryKey(MainWindow.LoggedinId); if (user.UserType == UserType.Constants.SYSTEM_ADMIN) { XtraMessageBox.Show(exp.Message); } else { XtraMessageBox.Show("Saving Error!", "Error", MessageBoxButtons.OK); } } } } else { XtraMessageBox.Show(valid, "Validation", MessageBoxButtons.OK, MessageBoxIcon.Stop); } }
public ReceiveDoc CreateInventoryReceive(Inventory inventory, int receiptID, Inventory.QuantityType quantityType, DateTime ethiopianDate, User user) { ItemUnit itemUnit = new ItemUnit(); itemUnit.LoadByPrimaryKey(inventory.UnitID); ReceiveDoc receiveDoc = new ReceiveDoc(); receiveDoc.AddNew(); receiveDoc.ItemID = inventory.ItemID; receiveDoc.UnitID = inventory.UnitID; receiveDoc.ManufacturerId = inventory.ManufacturerID; receiveDoc.StoreID = inventory.ActivityID; receiveDoc.Date = ethiopianDate; receiveDoc.EurDate = DateTimeHelper.ServerDateTime; receiveDoc.PhysicalStoreID = inventory.PhysicalStoreID; receiveDoc.SetColumn("BatchNo", inventory.GetColumn("BatchNo")); decimal quantity = quantityType == Inventory.QuantityType.Sound ? inventory.InventorySoundQuantity : quantityType == Inventory.QuantityType.Damaged ? inventory.InventoryDamagedQuantity :inventory.InventoryExpiredQuantity; if (quantityType == Inventory.QuantityType.Damaged) { receiveDoc.ShortageReasonID = ShortageReasons.Constants.DAMAGED; } receiveDoc.Quantity = receiveDoc.QuantityLeft = quantity * itemUnit.QtyPerUnit; receiveDoc.NoOfPack = receiveDoc.InvoicedNoOfPack = quantity; receiveDoc.QtyPerPack = itemUnit.QtyPerUnit; receiveDoc.SetColumn("ExpDate", inventory.GetColumn("ExpiryDate")); receiveDoc.Out = false; receiveDoc.ReceivedBy = user.UserName; receiveDoc.StoreID = inventory.ActivityID; receiveDoc.RefNo = "BeginningBalance"; decimal cost = 0; decimal margin = 0; if (!inventory.IsColumnNull("Cost")) { cost = inventory.Cost; } if (!inventory.IsColumnNull("Margin")) { margin = inventory.Margin; } receiveDoc.Cost = Convert.ToDouble(cost); receiveDoc.PricePerPack = Convert.ToDouble(cost); receiveDoc.UnitCost = cost; receiveDoc.Margin = Convert.ToDouble(margin); receiveDoc.SellingPrice = Convert.ToDouble(BLL.Settings.IsCenter ? cost : cost * (1 + margin)); receiveDoc.SupplierID = 2; //TODO: HARDCODE WARNING WARNING WARNING receiveDoc.DeliveryNote = false; receiveDoc.Confirmed = true; receiveDoc.ConfirmedDateTime = DateTimeHelper.ServerDateTime; receiveDoc.ReturnedStock = false; receiveDoc.ReceiptID = receiptID; receiveDoc.RefNo = "BeginningBalance"; receiveDoc.InventoryPeriodID = inventory.InventoryPeriodID; receiveDoc.IsDamaged = (quantityType == Inventory.QuantityType.Damaged || quantityType == Inventory.QuantityType.Expired); receiveDoc.Save(); //Now Save the ReceiveDocConfirmation ReceiveDocConfirmation rdConf = new ReceiveDocConfirmation(); rdConf.AddNew(); rdConf.ReceiveDocID = receiveDoc.ID; rdConf.ReceivedByUserID = user.ID; rdConf.ReceiptConfirmationStatusID = ReceiptConfirmationStatus.Constants.RECEIVE_QUANTITY_CONFIRMED; rdConf.Save(); //TODO: Create Receive Pallet Here PalletLocation palletLocation = new PalletLocation(); palletLocation.LoadByPrimaryKey(quantityType != Inventory.QuantityType.Damaged ? inventory.PalletLocationID : inventory.DamagedPalletLocationID); ReceivePallet receivePallet = new ReceivePallet(); receivePallet.AddNew(); receivePallet.Balance = quantity * itemUnit.QtyPerUnit; receivePallet.ReceivedQuantity = quantity * itemUnit.QtyPerUnit; receivePallet.ReservedStock = 0; receivePallet.ReceiveID = receiveDoc.ID; if (palletLocation.IsColumnNull("PalletID")) { Pallet pallet = new Pallet(); pallet.AddNew(); pallet.Save(); palletLocation.PalletID = pallet.ID; palletLocation.Save(); } receivePallet.PalletID = palletLocation.PalletID; receivePallet.PalletLocationID = palletLocation.ID; receivePallet.BoxSize = 0; receivePallet.IsOriginalReceive = true; receivePallet.Save(); return(receiveDoc); }
private void btnSave_Click(object sender, EventArgs e) { var transfer = new Transfer(); var newreceiveDoc = new ReceiveDoc(); var receiveDoc = new ReceiveDoc(); var issuedoc = new IssueDoc(); var valid = ValidateFields(); if (valid == "true") { if (XtraMessageBox.Show("Are you sure you want to save this transaction?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { try{ var dtRecGrid = (DataTable)receivingGrid.DataSource; for (int i = 0; i < dtRecGrid.Rows.Count; i++) { transfer.AddNew(); var receiveid = Convert.ToInt32(dtRecGrid.Rows[i]["RecID"]); transfer.ItemID = _itemID = Convert.ToInt32(dtRecGrid.Rows[i]["ID"]); transfer.RecID = receiveid; transfer.BatchNo = dtRecGrid.Rows[i]["Batch No"].ToString(); transfer.FromStoreID = Convert.ToInt32(lkFromStore.EditValue); transfer.ToStoreID = Convert.ToInt32(lkToStore.EditValue); transfer.Quantity = Convert.ToInt64(dtRecGrid.Rows[i]["Qty To Transfer"]); transfer.RefNo = txtRefNo.Text; transfer.UnitID = VisibilitySetting.HandleUnits == 1 ? 0 : Convert.ToInt32(dtRecGrid.Rows[i]["UnitID"]); DateTime xx = dtRecDate.Value; dtRecDate.CustomFormat = "MM/dd/yyyy"; new DateTime(); transfer.Date = ConvertDate.DateConverter(dtRecDate.Text); ConvertDate.DateConverter(dtRecDate.Text); dtRecDate.IsGregorianCurrentCalendar = true; transfer.EurDate = dtRecDate.Value; dtRecDate.IsGregorianCurrentCalendar = false; transfer.TransferReason = txtTransferReason.Text; transfer.ApprovedBy = txtApprovedBy.Text; transfer.TransferRequestedBy = txtRequestedBy.Text; transfer.Save(); transfer.GetTransfered(receiveid, _itemID, Convert.ToInt32(lkFromStore.EditValue)); issuedoc.AddNew(); issuedoc.StoreId = transfer.FromStoreID; issuedoc.ItemID = transfer.ItemID; issuedoc.Quantity = transfer.Quantity; issuedoc.Date = transfer.Date; issuedoc.EurDate = transfer.EurDate; issuedoc.BatchNo = transfer.BatchNo; issuedoc.UnitID = transfer.UnitID; issuedoc.RecievDocID = transfer.RecID; issuedoc.IsTransfer = true; issuedoc.RefNo = transfer.RefNo; var allstores = new Stores(); allstores.LoadByPrimaryKey(transfer.ToStoreID); issuedoc.ReceivingUnitID = (int)allstores.GetColumn("ReceivingUnitID"); issuedoc.Save(); receiveDoc.GetReceivedItems(receiveid, _itemID, Convert.ToInt32(lkFromStore.EditValue)); receiveDoc.QuantityLeft = receiveDoc.QuantityLeft - transfer.Quantity; newreceiveDoc.AddNew(); newreceiveDoc.StoreID = transfer.ToStoreID; newreceiveDoc.RefNo = transfer.RefNo; newreceiveDoc.BatchNo = transfer.BatchNo; newreceiveDoc.ItemID = transfer.ItemID; newreceiveDoc.Quantity = transfer.Quantity; newreceiveDoc.QuantityLeft = transfer.Quantity; newreceiveDoc.NoOfPack = Convert.ToInt32(transfer.Quantity) / receiveDoc.QtyPerPack; newreceiveDoc.QtyPerPack = receiveDoc.QtyPerPack; newreceiveDoc.Cost = receiveDoc.Cost; newreceiveDoc.Date = transfer.Date; newreceiveDoc.EurDate = transfer.EurDate; newreceiveDoc.UnitID = transfer.UnitID; newreceiveDoc.Out = false; newreceiveDoc.ReceivedBy = transfer.ApprovedBy; newreceiveDoc.ExpDate = receiveDoc.ExpDate; allstores.LoadByPrimaryKey(transfer.FromStoreID); newreceiveDoc.SupplierID = (int)allstores.GetColumn("SupplierID"); newreceiveDoc.BoxLevel = 1; newreceiveDoc.Save(); receiveDoc.Save(); } XtraMessageBox.Show("Transaction Successfully Saved!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); ResetFields(); } catch (Exception exp) { XtraMessageBox.Show(exp.InnerException.Message, "Error"); } } } else { XtraMessageBox.Show(valid, "Validation", MessageBoxButtons.OK, MessageBoxIcon.Stop); } }
private ReceiveDoc CreateReceiveDocForInventory(Inventory inventory, int confirmationStatusID, decimal foundQty, int receiptID, DateTime convertedEthDate, User user, string remark) { ReceiveDoc newReceiveDoc = new ReceiveDoc(); newReceiveDoc.AddNew(); newReceiveDoc.SetColumn("BatchNo", inventory.GetColumn("BatchNo")); newReceiveDoc.ItemID = inventory.ItemID; newReceiveDoc.ManufacturerId = inventory.ManufacturerID; newReceiveDoc.SetColumn("UnitID", inventory.UnitID); if (!inventory.IsColumnNull("SupplierID")) { newReceiveDoc.SupplierID = inventory.SupplierID; } BLL.ItemUnit iu = new ItemUnit(); iu.LoadByPrimaryKey(inventory.UnitID); newReceiveDoc.Quantity = newReceiveDoc.QuantityLeft = foundQty * iu.QtyPerUnit; newReceiveDoc.NoOfPack = foundQty; newReceiveDoc.InvoicedNoOfPack = foundQty; newReceiveDoc.QtyPerPack = iu.QtyPerUnit; newReceiveDoc.Date = convertedEthDate; newReceiveDoc.SetColumn("ExpDate", inventory.GetColumn("ExpiryDate")); newReceiveDoc.Out = false; newReceiveDoc.ReceivedBy = user.UserName; newReceiveDoc.StoreID = inventory.ActivityID; newReceiveDoc.SetColumn("LocalBatchNo", inventory.GetColumn("BatchNo")); newReceiveDoc.RefNo = receiptID.ToString(); newReceiveDoc.SetColumn("Cost", inventory.GetColumn("Cost")); newReceiveDoc.SetColumn("IsApproved", DBNull.Value); newReceiveDoc.EurDate = DateTimeHelper.ServerDateTime; newReceiveDoc.SetColumn("SellingPrice", inventory.GetColumn("SellingPrice")); newReceiveDoc.SetColumn("UnitCost", inventory.GetColumn("Cost")); newReceiveDoc.SetColumn("Cost", inventory.GetColumn("Cost")); newReceiveDoc.SetColumn("PricePerPack", inventory.GetColumn("Cost")); newReceiveDoc.SetColumn("DeliveryNote", DBNull.Value); newReceiveDoc.Confirmed = true; newReceiveDoc.ConfirmedDateTime = DateTimeHelper.ServerDateTime; newReceiveDoc.ReturnedStock = false; newReceiveDoc.ReceiptID = receiptID; newReceiveDoc.SetColumn("Margin", inventory.GetColumn("Margin")); newReceiveDoc.RefNo = "BeginningBalance"; if (!string.IsNullOrEmpty(remark)) { newReceiveDoc.IsDamaged = false; } if (!string.IsNullOrEmpty(remark)) { newReceiveDoc.Remark = remark; } newReceiveDoc.Save(); //Now Save the ReceiveDocConfirmation ReceiveDocConfirmation rdConf = new ReceiveDocConfirmation(); rdConf.AddNew(); rdConf.ReceiveDocID = newReceiveDoc.ID; rdConf.ReceivedByUserID = user.ID; rdConf.ReceiptConfirmationStatusID = confirmationStatusID; rdConf.Save(); return(newReceiveDoc); }
private ReceiveDoc CreateReceiveDocForInventory(Inventory inventory, int confirmationStatusID, decimal foundQty, int receiptID, DateTime convertedEthDate, User user,string remark) { ReceiveDoc newReceiveDoc = new ReceiveDoc(); newReceiveDoc.AddNew(); newReceiveDoc.SetColumn("BatchNo", inventory.GetColumn("BatchNo")); newReceiveDoc.ItemID = inventory.ItemID; newReceiveDoc.ManufacturerId = inventory.ManufacturerID; newReceiveDoc.SetColumn("UnitID", inventory.UnitID); if (!inventory.IsColumnNull("SupplierID")) newReceiveDoc.SupplierID = inventory.SupplierID; BLL.ItemUnit iu = new ItemUnit(); iu.LoadByPrimaryKey(inventory.UnitID); newReceiveDoc.Quantity = newReceiveDoc.QuantityLeft = foundQty*iu.QtyPerUnit; newReceiveDoc.NoOfPack = foundQty; newReceiveDoc.InvoicedNoOfPack = foundQty; newReceiveDoc.QtyPerPack = iu.QtyPerUnit; newReceiveDoc.Date = convertedEthDate; newReceiveDoc.SetColumn("ExpDate", inventory.GetColumn("ExpiryDate")); newReceiveDoc.Out = false; newReceiveDoc.ReceivedBy = user.UserName; newReceiveDoc.StoreID = inventory.ActivityID; newReceiveDoc.SetColumn("LocalBatchNo", inventory.GetColumn("BatchNo")); newReceiveDoc.RefNo = receiptID.ToString(); newReceiveDoc.SetColumn("Cost", inventory.GetColumn("Cost")); newReceiveDoc.SetColumn("IsApproved", DBNull.Value); newReceiveDoc.EurDate = DateTimeHelper.ServerDateTime; newReceiveDoc.SetColumn("SellingPrice", inventory.GetColumn("SellingPrice")); newReceiveDoc.SetColumn("UnitCost", inventory.GetColumn("Cost")); newReceiveDoc.SetColumn("Cost", inventory.GetColumn("Cost")); newReceiveDoc.SetColumn("PricePerPack", inventory.GetColumn("Cost")); newReceiveDoc.SetColumn("DeliveryNote", DBNull.Value); newReceiveDoc.Confirmed = true; newReceiveDoc.ConfirmedDateTime = DateTimeHelper.ServerDateTime; newReceiveDoc.ReturnedStock = false; newReceiveDoc.ReceiptID = receiptID; newReceiveDoc.SetColumn("Margin", inventory.GetColumn("Margin")); newReceiveDoc.RefNo = "BeginningBalance"; if(!string.IsNullOrEmpty(remark)) newReceiveDoc.IsDamaged = false; if (!string.IsNullOrEmpty(remark)) { newReceiveDoc.Remark = remark; } newReceiveDoc.Save(); //Now Save the ReceiveDocConfirmation ReceiveDocConfirmation rdConf = new ReceiveDocConfirmation(); rdConf.AddNew(); rdConf.ReceiveDocID = newReceiveDoc.ID; rdConf.ReceivedByUserID = user.ID; rdConf.ReceiptConfirmationStatusID = confirmationStatusID; rdConf.Save(); return newReceiveDoc; }
public ReceiveDoc CreateInventoryReceive(Inventory inventory,int receiptID,Inventory.QuantityType quantityType,DateTime ethiopianDate,User user) { ItemUnit itemUnit = new ItemUnit(); itemUnit.LoadByPrimaryKey(inventory.UnitID); ReceiveDoc receiveDoc = new ReceiveDoc(); receiveDoc.AddNew(); receiveDoc.ItemID = inventory.ItemID; receiveDoc.UnitID = inventory.UnitID; receiveDoc.ManufacturerId = inventory.ManufacturerID; receiveDoc.StoreID = inventory.ActivityID; receiveDoc.Date = ethiopianDate; receiveDoc.EurDate = DateTimeHelper.ServerDateTime; receiveDoc.PhysicalStoreID = inventory.PhysicalStoreID; receiveDoc.SetColumn("BatchNo", inventory.GetColumn("BatchNo")); decimal quantity = quantityType == Inventory.QuantityType.Sound ? inventory.InventorySoundQuantity : quantityType == Inventory.QuantityType.Damaged ? inventory.InventoryDamagedQuantity :inventory.InventoryExpiredQuantity; if(quantityType == Inventory.QuantityType.Damaged) receiveDoc.ShortageReasonID = ShortageReasons.Constants.DAMAGED; receiveDoc.Quantity = receiveDoc.QuantityLeft = quantity * itemUnit.QtyPerUnit; receiveDoc.NoOfPack = receiveDoc.InvoicedNoOfPack = quantity; receiveDoc.QtyPerPack = itemUnit.QtyPerUnit; receiveDoc.SetColumn("ExpDate", inventory.GetColumn("ExpiryDate")); receiveDoc.Out = false; receiveDoc.ReceivedBy = user.UserName; receiveDoc.StoreID = inventory.ActivityID; receiveDoc.RefNo = "BeginningBalance"; decimal cost = 0; decimal margin = 0; if (!inventory.IsColumnNull("Cost")) { cost = inventory.Cost; } if(!inventory.IsColumnNull("Margin")) { margin = inventory.Margin; } receiveDoc.Cost = Convert.ToDouble(cost); receiveDoc.PricePerPack = Convert.ToDouble(cost); receiveDoc.UnitCost = cost; receiveDoc.Margin = Convert.ToDouble(margin); receiveDoc.SellingPrice = Convert.ToDouble(BLL.Settings.IsCenter ? cost : cost * (1 + margin)); receiveDoc.SupplierID = 2; //TODO: HARDCODE WARNING WARNING WARNING receiveDoc.DeliveryNote = false; receiveDoc.Confirmed = true; receiveDoc.ConfirmedDateTime = DateTimeHelper.ServerDateTime; receiveDoc.ReturnedStock = false; receiveDoc.ReceiptID = receiptID; receiveDoc.RefNo = "BeginningBalance"; receiveDoc.InventoryPeriodID = inventory.InventoryPeriodID; receiveDoc.IsDamaged = (quantityType == Inventory.QuantityType.Damaged || quantityType == Inventory.QuantityType.Expired); receiveDoc.Save(); //Now Save the ReceiveDocConfirmation ReceiveDocConfirmation rdConf = new ReceiveDocConfirmation(); rdConf.AddNew(); rdConf.ReceiveDocID = receiveDoc.ID; rdConf.ReceivedByUserID = user.ID; rdConf.ReceiptConfirmationStatusID = ReceiptConfirmationStatus.Constants.RECEIVE_QUANTITY_CONFIRMED; rdConf.Save(); //TODO: Create Receive Pallet Here PalletLocation palletLocation = new PalletLocation(); palletLocation.LoadByPrimaryKey(quantityType != Inventory.QuantityType.Damaged ? inventory.PalletLocationID : inventory.DamagedPalletLocationID); ReceivePallet receivePallet = new ReceivePallet(); receivePallet.AddNew(); receivePallet.Balance = quantity * itemUnit.QtyPerUnit; receivePallet.ReceivedQuantity = quantity * itemUnit.QtyPerUnit; receivePallet.ReservedStock = 0; receivePallet.ReceiveID = receiveDoc.ID; if(palletLocation.IsColumnNull("PalletID")) { Pallet pallet = new Pallet(); pallet.AddNew(); pallet.Save(); palletLocation.PalletID = pallet.ID; palletLocation.Save(); } receivePallet.PalletID = palletLocation.PalletID; receivePallet.PalletLocationID =palletLocation.ID; receivePallet.BoxSize = 0; receivePallet.IsOriginalReceive = true; receivePallet.Save(); return receiveDoc; }
private void BtnAddBatchClick(object sender, EventArgs e) { if (!dxValidationProvider1.Validate()) { return; } var rec = new ReceiveDoc(); var yEnd = new YearEnd(); switch (VisibilitySetting.HandleUnits) { case 1: { rec.AddNew(); rec.ItemID = _itemid; rec.BatchNo = txtBatchNo.Text; rec.StoreID = _storeid; rec.ExpDate = (DateTime)dateEditExpiryDate.EditValue; rec.Date = _date; rec.UnitID = 0; rec.RefNo = txtRefNo.Text; rec.Out = false; rec.EurDate = DateTime.Now.Subtract(TimeSpan.FromDays(35)); rec.NoOfPack = Convert.ToInt32(txtPackQty.Text); rec.QtyPerPack = Convert.ToInt32(txtQtyPerPack.Text); rec.Quantity = (Convert.ToInt32(txtPackQty.Text)) * (Convert.ToInt32(txtQtyPerPack.Text)); rec.QuantityLeft = (Convert.ToInt32(txtPackQty.Text)) * (Convert.ToInt32(txtQtyPerPack.Text)); rec.Cost = Convert.ToDouble(txtPrice.Text); rec.Save(); yEnd.AddNew(); yEnd.ItemID = _itemid; yEnd.StoreID = _storeid; yEnd.Year = _date.Year; yEnd.AutomaticallyEntered = true; yEnd.BBalance = 0; yEnd.EBalance = 0; yEnd.Save(); } break; default: { rec.AddNew(); rec.ItemID = _itemid; rec.BatchNo = txtBatchNo.Text; rec.StoreID = _storeid; rec.UnitID = _unitid; rec.ExpDate = (DateTime)dateEditExpiryDate.EditValue; rec.NoOfPack = Convert.ToInt32(txtPackQty.Text); rec.Quantity = Convert.ToInt32(txtPackQty.Text); rec.QuantityLeft = Convert.ToInt32(txtPackQty.Text); rec.QtyPerPack = Convert.ToInt32(txtQtyPerPack.Text); rec.Date = _date; rec.RefNo = txtRefNo.Text; rec.Out = false; rec.EurDate = DateTime.Now.Subtract(TimeSpan.FromDays(35)); rec.Cost = Convert.ToDouble(txtPrice.Text); rec.Save(); yEnd.AddNew(); yEnd.ItemID = _itemid; yEnd.StoreID = _storeid; yEnd.UnitID = _unitid; yEnd.AutomaticallyEntered = true; yEnd.BBalance = 0; yEnd.EBalance = 0; yEnd.Save(); } break; } XtraMessageBox.Show("New Batch successfully added.", "Success"); Close(); }
private void btnSave_Click(object sender, EventArgs e) { var rec = new ReceiveDoc(); var itm = new Items(); //var itemprogram = new ProgramProduct(); string valid = ValidateFields(); if (valid == "true") { if ( XtraMessageBox.Show("Are you sure you want to save this transaction?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { try { for (int i = 0; i < dtRecGrid.Rows.Count; i++) { if (dtRecGrid.Rows[i]["Expiry Date"] != DBNull.Value) { if (Convert.ToDateTime(dtRecGrid.Rows[i]["Expiry Date"]) <= DateTime.Now) { var dialog = XtraMessageBox.Show( "The item " + dtRecGrid.Rows[i]["Item Name"].ToString() + " has already expired. Are you sure you want to receive it?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dialog == DialogResult.No) { return; } } } rec.AddNew(); rec.StoreID = Convert.ToInt32(cboStores.EditValue); rec.RefNo = txtRefNo.Text.Trim(); rec.Remark = txtRemark.Text; rec.ReceivedBy = txtReceivedBy.Text; DateTime xx = dtRecDate.Value; dtRecDate.CustomFormat = "MM/dd/yyyy"; DateTime dtRec = new DateTime(); rec.Date = ConvertDate.DateConverter(dtRecDate.Text); dtRec = ConvertDate.DateConverter(dtRecDate.Text); dtRecDate.IsGregorianCurrentCalendar = true; rec.EurDate = dtRecDate.Value; dtRecDate.IsGregorianCurrentCalendar = false; rec.ItemID = Convert.ToInt32(dtRecGrid.Rows[i][0]); switch (VisibilitySetting.HandleUnits) { case 1: rec.UnitID = 0; rec.QtyPerPack = Convert.ToInt32(dtRecGrid.Rows[i]["Qty/Pack"]); break; case 2: rec.UnitID = Convert.ToInt32(dtRecGrid.Rows[i]["UnitID"]); rec.QtyPerPack = 1; break; case 3: rec.UnitID = Convert.ToInt32(dtRecGrid.Rows[i]["UnitID"]); rec.QtyPerPack = 1; break; } rec.NoOfPack = Convert.ToInt32(dtRecGrid.Rows[i]["Pack Qty"]); rec.Quantity = rec.NoOfPack * rec.QtyPerPack; rec.QuantityLeft = rec.Quantity; if (dtRecGrid.Rows[i]["Price/Pack"] != null && dtRecGrid.Rows[i]["Price/Pack"].ToString() != "") { double pre = Convert.ToDouble(dtRecGrid.Rows[i]["Price/Pack"]) / rec.QtyPerPack; rec.Cost = Convert.ToDouble(pre); } else { rec.Cost = 0; } itm.LoadByPrimaryKey(Convert.ToInt32(dtRecGrid.Rows[i]["ID"])); rec.BatchNo = dtRecGrid.Rows[i][8].ToString(); if (dtRecGrid.Rows[i]["Expiry Date"] != DBNull.Value) { rec.ExpDate = Convert.ToDateTime(dtRecGrid.Rows[i]["Expiry Date"]); } if (dtRecGrid.Rows[i]["Internal Drug Code"] != DBNull.Value) { rec.InternalDrugCode = Convert.ToString(dtRecGrid.Rows[i]["Internal Drug Code"]); } rec.SupplierID = Convert.ToInt32(cboSupplier.EditValue); rec.SubProgramID = Convert.ToInt32(cboProgram.EditValue); ProgramProduct pr = new ProgramProduct(); pr.LoadByProgramProductByItemId(rec.ItemID, rec.StoreID); if (pr.RowCount == 0) { pr.AddNew(); pr.ItemID = rec.ItemID; pr.ProgramID = (rec.StoreID == 8)? 1000: 1001; pr.StoreID = rec.StoreID; pr.Save(); } string batch = DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + rec.ItemID.ToString(); rec.LocalBatchNo = batch; rec.Out = false; rec.IsApproved = false; dtRecDate.Value = xx; rec.Save(); //check if there is any data on stockoutLog about this item on this store //and update its enddate to today StockoutLog stockoutLog = new StockoutLog(); DataTable tblStockoutLog = stockoutLog.LoadByStoreAndItemId(rec.ItemID, rec.StoreID, true); if (tblStockoutLog != null) { if (tblStockoutLog.Rows.Count > 0) { stockoutLog.LoadByPrimaryKey(int.Parse(tblStockoutLog.Rows[0]["ID"].ToString())); stockoutLog.EndDate = DateTime.Today; stockoutLog.Save(); } } //itemprogram.LoadByOldProgramIdAndItemId(Convert.ToInt32(cboStores.EditValue), // Convert.ToInt32(dtRecGrid.Rows[i][0]), // Convert.ToInt32(cboProgram.EditValue)); //if (itemprogram.RowCount != 0) //{ // continue; //} //itemprogram.AddNew(); //itemprogram.StoreID = Convert.ToInt32(cboStores.EditValue); //itemprogram.ItemID = Convert.ToInt32(dtRecGrid.Rows[i][0]); //itemprogram.ProgramID = Convert.ToInt32(cboProgram.EditValue); //itemprogram.Save(); } XtraMessageBox.Show("Transaction Successfully Saved!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); GeneralInfo gn = new GeneralInfo(); gn.LoadAll(); if (gn.UsesModel) { int userID = MainWindow.LoggedinId; User us = new User(); us.LoadByPrimaryKey(userID); string printedby = string.Format("Printed by {0} on {1} , HCMIS {2}", us.FullName, DateTime.Today.ToShortDateString(), Program.HCMISVersionString); var modelprint = new Model19 { PrintedBy = { Text = printedby }, xrStore = { Text = cboStores.Text } }; var tbl1 = ((DataTable)receivingGrid.DataSource); tbl1.TableName = "Model19"; var dtset = new DataSet(); dtset.Tables.Add(tbl1.Copy()); modelprint.ReportUnit = DevExpress.XtraReports.UI.ReportUnit.TenthsOfAMillimeter; modelprint.PaperKind = System.Drawing.Printing.PaperKind.Custom; //modelprint.PageHeight = modelprint.PageHeight / 10; //Convert.ToInt32(BLL.Settings.PaperHeightCredit); // modelprint.PageWidth = modelprint.PageHeight / 10; //Convert.ToInt32(BLL.Settings.PaperWidthCredit); modelprint.DataSource = dtset; modelprint.Landscape = true; //XtraMessageBox.Show(string.Format("You are about to print {0} pages!", modelprint.PrintingSystem.Pages.Count), "Success", MessageBoxButtons.OK, // MessageBoxIcon.Information); modelprint.ShowPreviewDialog(); } ResetFields(); // mgr.CommitTransaction(); } catch (Exception exp) { //mgr.RollbackTransaction(); BLL.User user = new User(); user.LoadByPrimaryKey(MainWindow.LoggedinId); if (user.UserType == UserType.Constants.SYSTEM_ADMIN) { XtraMessageBox.Show(exp.Message); } else { XtraMessageBox.Show("Saving Error!", "Error", MessageBoxButtons.OK); } } } } else { XtraMessageBox.Show(valid, "Validation", MessageBoxButtons.OK, MessageBoxIcon.Stop); } }