/// <summary> /// Needs to be the first function to be called when saving a new receive doc entry. /// </summary> /// <param name="rec"></param> /// <param name="receiptID"></param> /// <param name="dr"></param> private void FillInReceiveDocInformation(ReceiveDoc rec, int receiptID, DataRowView dr) { try { rec.GetColumn("GUID"); } catch { rec.AddColumn("GUID", typeof(string)); //rec.AddColumn("IsDamaged", typeof(bool)); //This is only used if the Check box is used to receive damaged receives (For SRM only) } rec.StoreID = Convert.ToInt32(lkAccounts.EditValue); rec.RefNo = txtRefNo.Text; rec.Remark = txtRemark.Text; rec.ReceivedBy = CurrentContext.LoggedInUserName; DateTime xx = dtRecDate.Value; dtRecDate.CustomFormat = "MM/dd/yyyy"; DateTime dtRec = new DateTime(); rec.Date = ConvertDate.DateConverter(dtRecDate.Text); dtRec = ConvertDate.DateConverter(dtRecDate.Text); rec.EurDate = BLL.DateTimeHelper.ServerDateTime; rec.ItemID = Convert.ToInt32(dr["ID"]); rec.NoOfPack = Convert.ToDecimal(dr["Pack Qty"]); rec.SetColumn("GUID", dr["GUID"].ToString()); rec.IsDamaged = Convert.ToBoolean(dr["IsDamaged"]); if (standardRecType == StandardReceiptType.iGRVOnline) { rec.SetColumn("PricePerPack", dr["Price/Pack"]); rec.SetColumn("Margin", dr["Margin"]); rec.SetColumn("UnitCost", dr["Price/Pack"]); } //TODO: This if is a garbage. Remove if (dr["InvoicedQty"] == DBNull.Value) { rec.InvoicedNoOfPack = rec.NoOfPack; } rec.InvoicedNoOfPack = srm ? Convert.ToDecimal(dr["IssuedQty"]) : Convert.ToDecimal(dr["OriginalInvoicedQty"]); rec.ManufacturerId = Convert.ToInt32(dr["Manufacturer"]); BLL.ItemManufacturer im = new BLL.ItemManufacturer(); im.LoadIMbyLevel(rec.ItemID, rec.ManufacturerId, 0); if (dr["UnitID"] != DBNull.Value) { // if unit has been set, pick the qty per pack from the unit rec.UnitID = Convert.ToInt32(dr["UnitID"]); ItemUnit itemUnit = new ItemUnit(); itemUnit.LoadByPrimaryKey(rec.UnitID); rec.QtyPerPack = itemUnit.QtyPerUnit; } else { rec.QtyPerPack = im.QuantityInBasicUnit; } rec.Quantity = rec.QuantityLeft = rec.NoOfPack * rec.QtyPerPack; try { if ((deliveryNoteType == DeliveryNoteType.NotSet)) { if (!BLL.Settings.HandleGRV && !srm) { rec.PricePerPack = Convert.ToDouble(dr["Price/Pack"]); double pre = (Convert.ToDouble(dr["Price/Pack"]) / 1); //rec.QtyPerPack); rec.Cost = pre; } rec.DeliveryNote = false; } else { rec.DeliveryNote = true; if (deliveryNoteType == DeliveryNoteType.Automatic) { rec.SetColumn("PricePerPack", dr["Price/Pack"]); rec.SetColumn("Margin", dr["Margin"]); rec.SetColumn("UnitCost", dr["Price/Pack"]); } } } catch { // catch the error if the recieve doesn't have cost information // NOTE: this shall never happen. } if (dr["Batch No"] != DBNull.Value) { rec.BatchNo = dr["Batch No"].ToString(); // receivingGrid.Rows[i].Cells[8].Value.ToString(); } if (dr["Expiry Date"] != DBNull.Value) { rec.ExpDate = Convert.ToDateTime(dr["Expiry Date"]); //receivingGrid.Rows[i].Cells[9].Value); } if (!srm) { rec.SupplierID = _supplierID; } else { rec.SupplierID = BLL.Supplier.CONSTANTS.RETURNED_FROM_FACILITY; //TODO: Returned From Supplier: To be removed. This is an unacceptable hack. rec.RefNo = lkSTVInvoiceNo.Text; if (string.IsNullOrEmpty(txtRemark.Text)) { XtraMessageBox.Show( "Please enter the reason for the SRM.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); throw new Exception("Reason not entered for SRM"); } else { rec.Remark = txtRemark.Text; } } rec.ReturnedStock = srm; if (srm && !chkSRMForOldSystemIssues.Checked) { rec.ReturnedFromIssueDocID = int.Parse(dr["IssueDocID"].ToString()); int issueDocID = int.Parse(dr["IssueDocID"].ToString()); BLL.IssueDoc iss = new IssueDoc(); iss.LoadByPrimaryKey(issueDocID); BLL.ReceiveDoc rd = new ReceiveDoc(); rd.LoadByPrimaryKey(iss.RecievDocID); //If it was a delivery note, then the return will not have price information associated with it. // HW-2189 decimal? UnitCost, SellingPrice, Margin; UnitCost = SellingPrice = Margin = null; if (!BLL.Settings.HandleGRV) { if (!iss.IsColumnNull("UnitCost") && iss.IsColumnNull("SellingPrice")) { UnitCost = iss.UnitCost; SellingPrice = iss.SellingPrice; Margin = !iss.IsColumnNull("Margin") ? iss.Margin : 0; } else if (!iss.IsColumnNull("Cost")) { Margin = !rd.IsColumnNull("Margin") ? Convert.ToDecimal(rd.Margin) : 0; SellingPrice = Convert.ToDecimal(iss.Cost / Convert.ToDouble(iss.NoOfPack)); UnitCost = BLL.Settings.IsCenter ? SellingPrice : SellingPrice / Convert.ToDecimal(Margin + 1); } } else { if (!iss.IsColumnNull("UnitCost") && iss.IsColumnNull("SellingPrice") && iss.UnitCost != 0 && iss.SellingPrice != 0) { UnitCost = iss.UnitCost; SellingPrice = iss.SellingPrice; Margin = !iss.IsColumnNull("Margin") ? iss.Margin : 0; } else if (!iss.IsColumnNull("Cost") && iss.Cost != 0) { Margin = !rd.IsColumnNull("Margin") ? Convert.ToDecimal(rd.Margin) : 0; SellingPrice = Convert.ToDecimal(iss.Cost / Convert.ToDouble(iss.NoOfPack)); UnitCost = BLL.Settings.IsCenter ? SellingPrice : SellingPrice / Convert.ToDecimal(Margin + 1); } } if (UnitCost.HasValue) { rec.PricePerPack = Convert.ToDouble(UnitCost); rec.Cost = Convert.ToDouble(UnitCost); rec.UnitCost = UnitCost.Value; } if (SellingPrice.HasValue) { rec.SellingPrice = Convert.ToDouble(SellingPrice); } if (Margin.HasValue) { rec.Margin = Convert.ToDouble(Margin); } if (!rd.IsColumnNull("SupplierID")) rec.SupplierID = rd.SupplierID; } rec.ReceiptID = receiptID; if (BLL.Settings.HandleGRV && !beginningBalance) { rec.RefNo = receiptID.ToString(); } else if (beginningBalance) { rec.RefNo = "BeginningBalance"; } //Needs to be fixed! Garbage string batch = DateTimeHelper.ServerDateTime.Day.ToString() + DateTimeHelper.ServerDateTime.Hour.ToString() + DateTimeHelper.ServerDateTime.Minute.ToString() + rec.ItemID.ToString(); rec.LocalBatchNo = batch; rec.Out = false; rec.IsApproved = false; if (dr["ShortageReasonID"] != DBNull.Value) { rec.ShortageReasonID = Convert.ToInt32(dr["ShortageReasonID"]); } var item = new Item(); item.LoadByPrimaryKey(Convert.ToInt32(dr["id"])); if (dr["ShortageReasonID"] == DBNull.Value && (item.NeedExpiryBatch || rec.ExpDate <= DateTimeHelper.ServerDateTime)) { rec.ShortageReasonID = ShortageReasons.Constants.DAMAGED; } dtRecDate.Value = xx; _receiptID = receiptID; //Assign it to the global variable so it can be used later on. }
private void unconfirmedMenuClicked_ItemClicked(object sender, ToolStripItemClickedEventArgs e) { DataRow dataRow = gridUnconfirmedView.GetFocusedDataRow(); if (dataRow != null) { if (e.ClickedItem.Text == "Delete") { if (DialogResult.Yes == XtraMessageBox.Show("Are you sure you would like to delete this?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question)) { DeleteIssueDoc(Convert.ToInt32(dataRow["ID"])); // Refresh it gridViewReferences_FocusedRowChanged(null, null); //XtraMessageBox.Show("Issue has been deleted"); } } else if (e.ClickedItem.Text == "Confirm") { IssueDoc doc = new IssueDoc(); doc.LoadByPrimaryKey(Convert.ToInt32(dataRow["ID"])); // do some validations if (doc.IsColumnNull("STVID")) { doc.STVID = _stvLogIdChosen.Value; doc.Save(); } // refresh XtraMessageBox.Show("You have confirmed the STV", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information); gridViewReferences_FocusedRowChanged(null, null); } } }