public List <Models.MOrders> GetAllbyid(int id) { List <Models.MOrders> model = new List <Models.MOrders>(); var query = from o in obj.Orders where Convert.ToString(o.id) == id.ToString() select o; foreach (var item in query) { Models.MOrders m = new Models.MOrders(); m.id = Convert.ToString(item.id); m.OrdersNo = item.OrderNo; m.OrderName = item.OrderName; m.OrderDescription = item.OrderDescription; m.Orderdate = Convert.ToString(item.OrderDate); m.deliverydate = Convert.ToString(item.deliveryDate); m.TotalCost = item.TotalCost; m.OrderType = item.OrderType; m.ClientId = Convert.ToString(item.ClientId); m.venorld = Convert.ToString(item.VendorId); m.FiscalYearld = Convert.ToString(item.FiscalYearId); m.eDate = Convert.ToString(item.eDate); model.Add(m); } return(model); }
public int Update(Models.MOrders model) { Common.Logger l = new Common.Logger(); string ClassName = "COrder"; try { var query = from o in obj.Orders where Convert.ToString(o.id) == Convert.ToString(model.id) select o; foreach (var item in query) { item.OrderNo = model.OrdersNo; item.OrderName = model.OrderName; item.OrderDescription = model.OrderDescription; item.OrderDate = Convert.ToDateTime(model.Orderdate); item.deliveryDate = Convert.ToDateTime(model.deliverydate); item.TotalCost = model.TotalCost; item.OrderType = model.OrderType; item.ClientId = Convert.ToInt32(model.ClientId); item.VendorId = Convert.ToInt32(model.venorld); item.FiscalYearId = Convert.ToInt32(model.FiscalYearld); item.eDate = Convert.ToDateTime(model.eDate); } l.Print(ClassName, Common.LogPointer.Info.ToString(), "Model Values id[" + model.id + "] OrderNo[" + model.OrdersNo + "] OrderName[" + model.OrderName + "] Orderdescription[" + model.OrderDescription + "] OrderDate[ " + model.Orderdate + " ] DeliveryDate[ " + model.deliverydate + " ] TotalCost [ " + model.TotalCost + " ] OrdersType [ " + model.ClientId + "] VendoeId [ " + model.venorld + " ] FiscalId [ " + model.FiscalYearld + "] eDate [ " + model.eDate + " ]"); obj.SubmitChanges(); l.Print(ClassName, Common.LogPointer.Info.ToString(), "Record Updated Successfully"); return(1); } catch (Exception ex) { l.Print(ClassName, Common.LogPointer.Error.ToString(), ex.ToString()); return(-1); } }
public List <Models.MOrders> GetAll() { List <Models.MOrders> model = new List <Models.MOrders>(); var query = from o in obj.Orders select o; foreach (var item in query) { Models.MOrders m = new Models.MOrders(); m.id = Convert.ToString(item.id); m.OrdersNo = item.OrderNo; m.OrderName = item.OrderName; m.OrderDescription = item.OrderDescription; m.Orderdate = Convert.ToString(item.OrderDate); m.deliverydate = Convert.ToString(item.deliveryDate); m.TotalCost = item.TotalCost; m.OrderType = item.OrderType; m.ClientId = Convert.ToString(item.ClientId); m.venorld = Convert.ToString(item.VendorId); m.FiscalYearld = Convert.ToString(item.FiscalYearId); m.eDate = Convert.ToString(item.eDate); m.InstallmentDueDate = item.InstallmentDueDate; m.Installments = item.Installments; m.ModeOfPayment = item.ModeOfPayment; m.WareHouseId = item.WareHouseId.ToString(); m.GrantorName = item.GrantorName; model.Add(m); } return(model); }
public int Save(Models.MOrders model) { Common.Logger l = new Common.Logger(); string ClassName = "COrders"; try { DB.Order bs = new DB.Order(); //bs.id = Convert.ToInt32(model.id); bs.OrderNo = model.OrdersNo; bs.OrderName = model.OrderName; bs.OrderDescription = model.OrderDescription; bs.OrderDate = Convert.ToDateTime(model.Orderdate); bs.deliveryDate = Convert.ToDateTime(model.deliverydate); bs.TotalCost = model.TotalCost; bs.OrderType = model.OrderType; bs.ClientId = Convert.ToInt32(model.ClientId); bs.VendorId = Convert.ToInt32(model.venorld); bs.FiscalYearId = Convert.ToInt32(model.FiscalYearld); bs.eDate = Convert.ToDateTime(model.eDate); bs.WareHouseId = Convert.ToInt32(model.WareHouseId); bs.Installments = model.Installments; bs.InstallmentDueDate = model.InstallmentDueDate; bs.ModeOfPayment = model.ModeOfPayment; bs.GrantorName = model.GrantorName; l.Print(ClassName, Common.LogPointer.Info.ToString(), "Model Values id[" + model.id + "] OrderNo[" + model.OrdersNo + "] OrderName[" + model.OrderName + "] Orderdescription[" + model.OrderDescription + "] OrderDate[ " + model.Orderdate + " ] DeliveryDate[ " + model.deliverydate + " ] TotalCost [ " + model.TotalCost + " ] OrdersType [ " + model.ClientId + "] VendoeId [ " + model.venorld + " ] FiscalId [ " + model.FiscalYearld + "] eDate [ " + model.eDate + " ]"); obj.Orders.InsertOnSubmit(bs); obj.SubmitChanges(); l.Print(ClassName, Common.LogPointer.Info.ToString(), "Record Inserted Successfully"); return(1); } catch (Exception ex) { l.Print(ClassName, Common.LogPointer.Error.ToString(), ex.ToString()); return(-1); } }
private int SaveOrders() { try { Classes.CDefaultCashAccount cda = new Classes.CDefaultCashAccount(); Classes.CDefaultAccount cba = new Classes.CDefaultAccount(); int OrderId = 0; string OrderNo = txtOrderNo.Text; string OrderName = txtOrderName.Text; string OrderDescription = txtOrderDescription.Text; string OrderDate = txtOrderDate.Text; string OrderDeliveryDate = txtDeliveryOfOrderDate.Text; string TotalCost = ReturnTotalOrderCost().ToString(); string OrderType = ddlOrderType.SelectedValue; string VendorId = ddlVendor.SelectedValue; string ClientId = ddlCustomer.SelectedValue; string WareHouseId = Session["WareHouse"].ToString(); string ModeOfPayment = ddlModeOfPayment.SelectedItem.Text; string Installments = txtInstallments.Text; string InstallmentDueDate = txtIntallmentDueDate.Text; if (OrderType == "1") { OrderType = "Order To Client"; } else if (OrderType == "2") { OrderType = "Order To Vendor"; } else { return(-2); } if (ModeOfPayment == "Please Select") { return(-8); } Models.MOrders mr = new Models.MOrders(); mr.OrdersNo = OrderNo; mr.OrderName = OrderName; mr.OrderDescription = OrderDescription; mr.Orderdate = OrderDate; mr.deliverydate = OrderDeliveryDate; mr.TotalCost = TotalCost; mr.OrderType = OrderType; mr.eDate = DateTime.Now.ToShortDateString(); mr.FiscalYearld = Session["FiscalYear"].ToString(); mr.WareHouseId = WareHouseId; mr.ModeOfPayment = ModeOfPayment; mr.Installments = Installments; mr.InstallmentDueDate = InstallmentDueDate; if (OrderType.EndsWith("Vendor")) { mr.venorld = VendorId; mr.ClientId = "-1"; if (Convert.ToInt32(VendorId) < 0) { return(-5); } } else { if (cbGrantor.Checked) { string GrantorName = txtGrantorInfo.Text; mr.GrantorName = GrantorName; } mr.ClientId = ClientId; mr.venorld = "-1"; if (Convert.ToInt32(ClientId) < 0) { return(-6); } } Classes.COrders co = new Classes.COrders(); if (Convert.ToInt32(WareHouseId) < 0) { return(-7); } //Saving Order if (co.Save(mr) < 0) { return(-1); } OrderId = co.GetLastOrderID(); if (OrderId < 0) { return(-3); } //Saving Order Products #region objects Models.MOrdersLine mor = new Models.MOrdersLine(); Models.MSaleTransactions ms = new Models.MSaleTransactions(); Classes.CSaleTransations ct = new Classes.CSaleTransations(); Classes.COrderOnline cor = new Classes.COrderOnline(); Models.MInventory mi = new Models.MInventory(); Classes.CInventory ci = new Classes.CInventory(); float OrderTotalCost = 0; #endregion for (int i = 0; i < grdProducts.Rows.Count; i++) { #region objects initializing mor = new Models.MOrdersLine(); ms = new Models.MSaleTransactions(); ct = new Classes.CSaleTransations(); cor = new Classes.COrderOnline(); mi = new Models.MInventory(); ci = new Classes.CInventory(); DropDownList ddlProduct = (DropDownList)grdProducts.Rows[i].FindControl("ddlProducts"); TextBox txtCp = (TextBox)grdProducts.Rows[i].FindControl("txtCp"); TextBox txtSp = (TextBox)grdProducts.Rows[i].FindControl("txtSp"); TextBox txtUnits = (TextBox)grdProducts.Rows[i].FindControl("txtUnits"); TextBox txtTotal = (TextBox)grdProducts.Rows[i].FindControl("txtTotal"); string ProductId = ddlProduct.SelectedValue; string CostPrice = txtCp.Text; string SalePrice = txtSp.Text; string TotalUnits = txtUnits.Text; string totalCost = (Convert.ToInt32(TotalUnits) * Convert.ToInt32(SalePrice)).ToString(); OrderTotalCost += Convert.ToSingle(totalCost); #endregion //OrderLine #region OrderLine mor.OrderId = OrderId.ToString(); mor.ProductId = ProductId; if (OrderType.EndsWith("Vendor")) { mor.SalePrice = CostPrice; } else { mor.SalePrice = SalePrice; } mor.unit = TotalUnits; mor.totalProductCost = totalCost; mor.eDate = DateTime.Now.ToShortDateString(); if (cor.Save(mor) < 0) { return(-3); } #endregion //Sale transaction #region Sale Transaction ms.ProductID = ProductId; ms.clientID = ClientId; ms.CostPrice = CostPrice; ms.SalePrice = SalePrice; ms.units = TotalUnits; ms.clientID = ClientId; ms.VendorID = VendorId; ms.date = Convert.ToDateTime(txtOrderDate.Text); ms.WareHouseId = WareHouseId; ms.OrderId = OrderId.ToString(); if (OrderType.EndsWith("Vendor")) { ms.transactionType = Common.Constants.SaleTransactions.Addition.ToString(); } else { ms.transactionType = Common.Constants.SaleTransactions.Deduction.ToString(); } //sale transaction if (ct.Save(ms) < 0) { return(-1); } #endregion //Inventory #region Inventory mi.ProductId = ProductId; mi.WareHouseld = WareHouseId; mi.Quantity = TotalUnits; mi.FiscalYearld = Session["FiscalYear"].ToString(); mi.Date = Convert.ToDateTime(OrderDate); mi.Cost = CostPrice; if (OrderType.EndsWith("Vendor")) { // mi.Cost = CostPrice; if (ci.Save(mi, Common.Constants.SaleTransactions.Addition) < 0) { return(-4); } } else { // mi.Cost = SalePrice; if (ci.Save(mi, Common.Constants.SaleTransactions.Deduction) < 0) { return(-4); } } #endregion //Accounts #region Accounts if (OrderType.Contains("Vendor")) { Classes.CJournal cj = new Classes.CJournal(); Models.MJournal mj = new Models.MJournal(); mj.acc_id = Convert.ToInt32(Common.Constants.Accounts.ChartOfAccounts.MerchandiseInventory).ToString(); mj.amount = totalCost; mj.des = "Order Of Inventory for Vendor of Product Id [" + ProductId + "] units [" + TotalUnits + "] "; mj.e_date = (OrderDate); mj.type = Common.Constants.Accounts.Type.Debit.ToString(); cj.Save(mj); mj = new Models.MJournal(); mj.acc_id = Convert.ToInt32(Common.Constants.Accounts.ChartOfAccounts.AccountsPayable).ToString(); mj.amount = totalCost; mj.des = "Order Of Inventory for Vendor of Product Id [" + ProductId + "] units [" + TotalUnits + "] "; mj.e_date = (OrderDate); mj.type = Common.Constants.Accounts.Type.Credit.ToString(); cj.Save(mj); } else if (OrderType.Contains("Client")) { Classes.CJournal cj = new Classes.CJournal(); Models.MJournal mj = new Models.MJournal(); mj.acc_id = Convert.ToInt32(Common.Constants.Accounts.ChartOfAccounts.AccountsRecievalbes).ToString(); mj.amount = totalCost; mj.des = "Order Of Inventory for Client of Product Id [" + ProductId + "] units [" + TotalUnits + "] "; mj.e_date = (OrderDate); mj.type = Common.Constants.Accounts.Type.Debit.ToString(); cj.Save(mj); cj = new Classes.CJournal(); mj = new Models.MJournal(); mj.acc_id = Convert.ToInt32(Common.Constants.Accounts.ChartOfAccounts.Sales).ToString(); mj.amount = totalCost; mj.des = "Order Of Inventory for Client of Product Id [" + ProductId + "] units [" + TotalUnits + "] "; mj.e_date = (OrderDate); mj.type = Common.Constants.Accounts.Type.Credit.ToString(); cj.Save(mj); cj = new Classes.CJournal(); mj = new Models.MJournal(); mj.acc_id = Convert.ToInt32(Common.Constants.Accounts.ChartOfAccounts.CostOfGoodsSold).ToString(); mj.amount = totalCost; mj.des = "Order Of Inventory for Client of Product Id [" + ProductId + "] units [" + TotalUnits + "] "; mj.e_date = (OrderDate); mj.type = Common.Constants.Accounts.Type.Debit.ToString(); cj.Save(mj); cj = new Classes.CJournal(); mj = new Models.MJournal(); mj.acc_id = Convert.ToInt32(Common.Constants.Accounts.ChartOfAccounts.MerchandiseInventory).ToString(); mj.amount = totalCost; mj.des = "Order Of Inventory for Client of Product Id [" + ProductId + "] units [" + TotalUnits + "] "; mj.e_date = (OrderDate); mj.type = Common.Constants.Accounts.Type.Credit.ToString(); cj.Save(mj); } #endregion } //Payments #region Payments Classes.CPayment cap = new Classes.CPayment(); Models.MPayments map = new Models.MPayments(); string TransactionId = ct.GetLastTransactionId().ToString(); if (ddlOrderType.SelectedItem.Text.Contains("Vendor")) { map.ClientId = -1; map.VendorId = Convert.ToInt32(VendorId); } else if (ddlOrderType.SelectedItem.Text.Contains("Client")) { map.ClientId = Convert.ToInt32(ClientId); map.VendorId = -1; } map.TransactionId = Convert.ToInt32(TransactionId); map.Paid = "0"; map.TotalCost = OrderTotalCost.ToString(); map.OrderId = OrderId; map.PaymentType = Common.Constants.PaymentTypes.Partial.ToString(); map.Paymentstate = Common.Constants.PaymentState.NotPaid.ToString(); if (cap.Save(map) < 0) { return(-4); } #endregion return(1); } catch { return(-1); } }