public void Save(SupplierInvoiceItem item) { var errors = item.GetValidationErrors(); errors.ThrowIfHasErrors(); var invoice = new tblSupplierInvoice(); if (item.Id != 0) { invoice = Db.Set <tblSupplierInvoice>().Single(x => x.Id == item.Id); } else { invoice = Db.CreateAndAdd <tblSupplierInvoice>(); } invoice.BuyDate = item.BuyDate; invoice.Notes = item.Notes; invoice.SupplierId = item.SupplierId; invoice.SupplierNumber = item.SupplierNumber; Db.SaveChanges(); item.Id = invoice.Id; }
private void pricemovkryptonButton1_Click(object sender, EventArgs e) { try { pricemovementkryptonDataGridView1.Rows.Clear(); if (m_part.ID == 0) { return; } IList movs = r_sir.GetSupplierInvoiceItem(m_part.ID); foreach (EventItem itm in movs) { int r = pricemovementkryptonDataGridView1.Rows.Add(); pricemovementkryptonDataGridView1[dateprcmovColumn1.Index, r].Value = itm.EVENT.TRANSACTION_DATE; pricemovementkryptonDataGridView1[codeprcmovColumn2.Index, r].Value = itm.EVENT.CODE; pricemovementkryptonDataGridView1[typeprcmovColumn1.Index, r].Value = itm.STOCK_CARD_ENTRY_TYPE.ToString(); pricemovementkryptonDataGridView1[qtyprcmovColumn1.Index, r].Value = itm.GetAmountInSmallestUnit(); pricemovementkryptonDataGridView1[unitprcmovColumn3.Index, r].Value = m_part.UNIT.CODE; switch (itm.STOCK_CARD_ENTRY_TYPE) { case StockCardEntryType.SupplierInvoice: SupplierInvoiceItem sii = (SupplierInvoiceItem)itm; SupplierInvoice si = (SupplierInvoice)sii.EVENT; si.SUPPLIER = (Supplier)r_sup.GetById(si.SUPPLIER); pricemovementkryptonDataGridView1[vendorprcmovColumn4.Index, r].Value = si.SUPPLIER.NAME; double c = sii.SUBTOTAL / sii.GetAmountInSmallestUnit(); c = r_ccy.ConvertToCurrency(si.CURRENCY, m_part.CURRENCY, c, si.TRANSACTION_DATE); pricemovementkryptonDataGridView1[priceprcmovColumn.Index, r].Value = c < 0 ? -c : c; break; case StockCardEntryType.StockTaking: StockTakingItems stk = (StockTakingItems)itm; StockTaking stkh = (StockTaking)itm.EVENT; double p = stk.TOTAL_AMOUNT / stk.GetAmountInSmallestUnit(); p = r_ccy.ConvertToCurrency(stkh.CURRENCY, m_part.CURRENCY, p, stkh.TRANSACTION_DATE); pricemovementkryptonDataGridView1[priceprcmovColumn.Index, r].Value = p < 0 ? -p : p; break; case StockCardEntryType.OpeningStock: OpeningStockItem opn = (OpeningStockItem)itm; OpeningStock opnh = (OpeningStock)itm.EVENT; double x = opn.TOTAL_AMOUNT / opn.GetAmountInSmallestUnit(); x = r_ccy.ConvertToCurrency(opnh.CURRENCY, m_part.CURRENCY, x, opnh.TRANSACTION_DATE); pricemovementkryptonDataGridView1[priceprcmovColumn.Index, r].Value = x < 0 ? -x : x; break; } pricemovementkryptonDataGridView1[statusMovementColumn.Index, r].Value = itm.EVENT.POSTED.ToString(); } UserSetting.AddNumberToGrid(pricemovementkryptonDataGridView1); updatePriceMovement(); } catch (Exception x) { KryptonMessageBox.Show(x.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
public ActionResult Edit(SupplierInvoiceItem item) { try { Service.SupplierInvoice.Save(item); return(RedirectToRouteNotify("EditSupplierInvoice", new { id = item.Id })); } catch (ValidationException ex) { AddModelErrors(ex); Service.SupplierInvoice.AppendData(item); return(View("~/Views/Admin/SupplierInvoices/Edit.cshtml", item)); } }
public SupplierInvoiceItem Edit(long id) { var item = new SupplierInvoiceItem(); if (id != 0) { item = Db.Set <tblSupplierInvoice>() .Include(x => x.tblSupplierInvoicePositions) .Where(x => x.Id == id) .Select(x => new SupplierInvoiceItem { Id = x.Id, BuyDate = x.BuyDate, Notes = x.Notes, SupplierId = x.SupplierId, SupplierNumber = x.SupplierNumber, Positions = x.tblSupplierInvoicePositions .Select(p => new SupplierInvoicePositionItem { Id = p.Id, ProductId = p.ProductId, ProductName = p.tblProduct.Name, Note = p.Note, Price = p.Price, Qty = p.Qty, SupplierInvoiceId = p.SupplierInvoiceId }) .ToList(), Files = x.tblFiles .Select(f => new FileItem { Id = f.Id, Path = f.Path, ProductId = f.ProductId, SupplierInvoiceId = f.SupplierInvoiceId, Description = f.Description, Position = f.Position ?? 0 }) .ToList() }) .Single(); } AppendData(item); return(item); }
private IList getItems() { IList items = new ArrayList(); for (int i = 0; i < itemsDataGrid.Rows.Count; i++) { Part p = (Part)itemsDataGrid[codeColumn.Index, i].Tag; if (itemsDataGrid[unitColumn.Index, i].Value == null) { continue; } Unit u = (Unit)Utils.FindEntityInList(itemsDataGrid[unitColumn.Index, i].Value.ToString(), m_units); if ((p == null) || (u == null)) { continue; } SupplierInvoiceItem st = (SupplierInvoiceItem)itemsDataGrid.Rows[i].Tag; if (st == null) { st = new SupplierInvoiceItem(); } itemsDataGrid.Rows[i].Tag = st; st.EVENT = m_si; st.PART = p; st.WAREHOUSE = (Warehouse)Utils.FindEntityInList(itemsDataGrid[warehouseColumn.Index, i].Value.ToString(), m_warehouses); st.QYTAMOUNT = Convert.ToDouble(itemsDataGrid[QtyColumn.Index, i].Value); st.UNIT = u; st.PRICE = Convert.ToDouble(itemsDataGrid[priceColumn.Index, i].Value); st.DISC_PERCENT = Convert.ToDouble(itemsDataGrid[discpercentColumn.Index, i].Value); st.DISC_AMOUNT = Convert.ToDouble(itemsDataGrid[discAmountColumn.Index, i].Value); st.TOTAL_DISCOUNT = Convert.ToDouble(itemsDataGrid[totalDiscColumn.Index, i].Value); st.NOTES = itemsDataGrid[notesColumn.Index, i].Value == null ? "" : itemsDataGrid[notesColumn.Index, i].Value.ToString(); st.DISC_ABC = itemsDataGrid[discabcColumn.Index, i].Value == null ? "" : itemsDataGrid[discabcColumn.Index, i].Value.ToString(); st.DISC_A = splitDiscString(st.DISC_ABC, 0); st.DISC_B = splitDiscString(st.DISC_ABC, 1); st.DISC_C = splitDiscString(st.DISC_ABC, 2); st.SUBTOTAL = Convert.ToDouble(itemsDataGrid[totalAmountColumn.Index, i].Value); GoodReceiveNoteItem grn = (GoodReceiveNoteItem)itemsDataGrid[GRNNoColumn.Index, i].Tag; st.GRN_ITEM = grn; if (st.QYTAMOUNT == 0) { continue; } items.Add(st); } return(items); }
private void loadMovement() { movemntkryptonDataGridView.Rows.Clear(); if (m_part.ID == 0) { return; } IList movs = r_part.GetAllEvents(m_part.ID); foreach (EventItem itm in movs) { int r = movemntkryptonDataGridView.Rows.Add(); movemntkryptonDataGridView[dateMovementColumn.Index, r].Value = itm.EVENT.TRANSACTION_DATE; movemntkryptonDataGridView[eventCodeMovementColumn.Index, r].Value = itm.EVENT.CODE; movemntkryptonDataGridView[eventTypeMovementColumn.Index, r].Value = itm.STOCK_CARD_ENTRY_TYPE.ToString(); movemntkryptonDataGridView[QtyMovementColumn.Index, r].Value = itm.GetAmountInSmallestUnit(); movemntkryptonDataGridView[unitMovementColumn.Index, r].Value = m_part.UNIT.CODE; movemntkryptonDataGridView[vendorMovementColumn.Index, r].Value = "-"; switch (itm.STOCK_CARD_ENTRY_TYPE) { case StockCardEntryType.PurchaseOrder: PurchaseOrderItem pi = (PurchaseOrderItem)itm; PurchaseOrder p = (PurchaseOrder)pi.EVENT; p.SUPPLIER = (Supplier)r_sup.GetById(p.SUPPLIER); movemntkryptonDataGridView[vendorMovementColumn.Index, r].Value = p.SUPPLIER.NAME; break; case StockCardEntryType.SalesOrder: SalesOrderItem soi = (SalesOrderItem)itm; SalesOrder so = (SalesOrder)soi.EVENT; so.CUSTOMER = (Customer)r_cus.GetById(so.CUSTOMER); movemntkryptonDataGridView[vendorMovementColumn.Index, r].Value = so.CUSTOMER.NAME; break; case StockCardEntryType.GoodReceiveNote: GoodReceiveNoteItem grni = (GoodReceiveNoteItem)itm; GoodReceiveNote grn = (GoodReceiveNote)grni.EVENT; grn.SUPPLIER = (Supplier)r_sup.GetById(grn.SUPPLIER); movemntkryptonDataGridView[vendorMovementColumn.Index, r].Value = grn.SUPPLIER.NAME; break; case StockCardEntryType.DeliveryOrder: DeliveryOrderItem doi = (DeliveryOrderItem)itm; DeliveryOrder dor = (DeliveryOrder)doi.EVENT; dor.CUSTOMER = (Customer)r_cus.GetById(dor.CUSTOMER); movemntkryptonDataGridView[vendorMovementColumn.Index, r].Value = dor.CUSTOMER.NAME; break; case StockCardEntryType.SupplierInvoice: SupplierInvoiceItem sii = (SupplierInvoiceItem)itm; SupplierInvoice si = (SupplierInvoice)sii.EVENT; si.SUPPLIER = (Supplier)r_sup.GetById(si.SUPPLIER); movemntkryptonDataGridView[vendorMovementColumn.Index, r].Value = si.SUPPLIER.NAME; break; case StockCardEntryType.CustomerInvoice: CustomerInvoiceItem cii = (CustomerInvoiceItem)itm; CustomerInvoice ci = (CustomerInvoice)cii.EVENT; ci.CUSTOMER = (Customer)r_cus.GetById(ci.CUSTOMER); movemntkryptonDataGridView[vendorMovementColumn.Index, r].Value = ci.CUSTOMER.NAME; break; case StockCardEntryType.PurchaseReturn: PurchaseReturnItem pri = (PurchaseReturnItem)itm; PurchaseReturn pr = (PurchaseReturn)pri.EVENT; pr.SUPPLIER = (Supplier)r_sup.GetById(pr.SUPPLIER); movemntkryptonDataGridView[vendorMovementColumn.Index, r].Value = pr.SUPPLIER.NAME; break; case StockCardEntryType.SalesReturn: SalesReturnItem sri = (SalesReturnItem)itm; SalesReturn sr = (SalesReturn)sri.EVENT; sr.CUSTOMER = (Customer)r_cus.GetById(sr.CUSTOMER); movemntkryptonDataGridView[vendorMovementColumn.Index, r].Value = sr.CUSTOMER.NAME; break; } movemntkryptonDataGridView[statusMovementColumn.Index, r].Value = itm.EVENT.POSTED.ToString(); } UserSetting.AddNumberToGrid(movemntkryptonDataGridView); }
public void AppendData(SupplierInvoiceItem item) { item.AvaliableSuppliers = Db.AllSuppliers(); }