public Vendor Add(int clientId, string vendorName, string address1, string address2, string address3, string contact, string phone, string fax, string url, string email) { var vend1 = new Ordering.Vendor() { ClientID = clientId, VendorName = vendorName, Address1 = address1, Address2 = address2, Address3 = address3, Contact = contact, Phone = phone, Fax = fax, URL = url, Email = email, Active = true }; DataSession.Insert(vend1); if (clientId > 0 && AutoAddStoreManagerVendor()) { // check for a store manager vendor with same name var storeManagerVendor = DataSession.Query <Ordering.Vendor>().Where(x => x.VendorName == vendorName && x.ClientID == 0).FirstOrDefault(); if (storeManagerVendor == null) { // add a store manager vendor if the name was not found var vend2 = new Ordering.Vendor() { ClientID = 0, VendorName = vendorName, Address1 = address1, Address2 = address2, Address3 = address3, Contact = contact, Phone = phone, Fax = fax, URL = url, Email = email, Active = true }; DataSession.Insert(vend2); } } return(CreateVendor(vend1)); }
private Ordering.Vendor GetVendorForCopy(Ordering.PurchaseOrder po) { var currentClientId = Context.CurrentUser.ClientID; Ordering.Vendor vendor; if (po.Client.ClientID == currentClientId || po.Vendor.ClientID == 0) { // current user is copying own order, or store manager order vendor = po.Vendor; } else { // current user is copying another user's order // check for a vendor for the current user that has the same name as the po vendor vendor = DataSession.Query <Ordering.Vendor>().Where(x => x.ClientID == currentClientId).ToList().FirstOrDefault(x => PurchaseOrderItems.CleanString(x.VendorName) == PurchaseOrderItems.CleanString(po.Vendor.VendorName)); if (vendor == null) { // make a copy vendor = new Ordering.Vendor() { Active = true, Address1 = po.Vendor.Address1, Address2 = po.Vendor.Address2, Address3 = po.Vendor.Address3, ClientID = currentClientId, Contact = po.Vendor.Contact, Email = po.Vendor.Email, Fax = po.Vendor.Fax, Items = new List <Ordering.PurchaseOrderItem>(), Phone = po.Vendor.Phone, URL = po.Vendor.URL, VendorName = po.Vendor.VendorName }; DataSession.Insert(vendor); } else { vendor.Active = true; //just in case } } return(vendor); }
public Vendor Copy(int toClientId, int fromVendorId) { var vend = Require <Ordering.Vendor>(x => x.VendorID, fromVendorId); var copy = new Ordering.Vendor() { ClientID = toClientId, VendorName = vend.VendorName, Address1 = vend.Address1, Address2 = vend.Address2, Address3 = vend.Address3, Contact = vend.Contact, Phone = vend.Phone, Fax = vend.Fax, URL = vend.URL, Email = vend.Email, Active = vend.Active }; DataSession.Insert(copy); return(CreateVendor(copy)); }
private Vendor CreateVendor(Ordering.Vendor vendor) { if (vendor == null) { return(null); } return(new Vendor() { VendorID = vendor.VendorID, ClientID = vendor.ClientID, VendorName = vendor.VendorName, Address1 = vendor.Address1, Address2 = vendor.Address2, Address3 = vendor.Address3, Contact = vendor.Contact, Phone = vendor.Phone, Fax = vendor.Fax, URL = vendor.URL, Email = vendor.Email, Active = vendor.Active }); }
private IList <Ordering.PurchaseOrderDetail> GetDetailsForCopy(Ordering.PurchaseOrder po, Ordering.PurchaseOrder copy, Ordering.Vendor vendor) { var currentClientId = Context.CurrentUser.ClientID; IList <Ordering.PurchaseOrderDetail> details; if (po.Client.ClientID == currentClientId || po.Vendor.ClientID == 0) { // current user is copying own order, or store manager vendor details = po.Details.Select(x => new Ordering.PurchaseOrderDetail() { Category = x.Category, IsInventoryControlled = x.IsInventoryControlled, Item = x.Item, PurchaseOrder = copy, Quantity = x.Quantity, ToInventoryDate = null, Unit = x.Unit, UnitPrice = x.UnitPrice }).ToList(); } else { // current user is copying another user's order details = new List <Ordering.PurchaseOrderDetail>(); // check for items for the current user that have the same description and partnum as the po detail items foreach (var d in po.Details) { var i = vendor.Items.FirstOrDefault(x => PurchaseOrderItems.CleanString(x.Description) == PurchaseOrderItems.CleanString(d.Item.Description) && PurchaseOrderItems.CleanString(x.PartNum) == PurchaseOrderItems.CleanString(d.Item.PartNum)); if (i == null) { // make a copy of the item i = new Ordering.PurchaseOrderItem() { Active = true, Description = d.Item.Description, Details = new List <Ordering.PurchaseOrderDetail>(), InventoryItemID = d.Item.InventoryItemID, PartNum = d.Item.PartNum, UnitPrice = d.Item.UnitPrice, Vendor = vendor }; DataSession.Insert(i); vendor.Items.Add(i); } else { i.Active = true; //just in case } var detail = new Ordering.PurchaseOrderDetail() { Category = d.Category, IsInventoryControlled = d.IsInventoryControlled, Item = i, PurchaseOrder = copy, Quantity = d.Quantity, ToInventoryDate = null, Unit = d.Unit, UnitPrice = d.UnitPrice }; details.Add(detail); } } return(details); }