public ActionResult save_supplier(string suppId, string suppName, string suppAddress, string suppCity, string suppPhone, string suppDesc, int mode = 0) { using (var db = new dbsmsEntities()) { if (String.IsNullOrEmpty(suppId)) { supplier data = new supplier(); data.name = suppName; data.phone = suppPhone; data.city = suppCity; data.address = suppAddress; data.description = suppDesc; data.status = 1; db.suppliers.Add(data); } else { supplier data = db.suppliers.Find(Convert.ToInt64(suppId)); data.name = suppName; data.address = suppAddress; data.phone = suppPhone; data.city = suppCity; data.description = suppDesc; } db.SaveChanges(); } TempData["success"] = "Your data has been saved."; if (mode != 0) { return(null); } return(RedirectToAction("Master_Supplier", "Master")); }
//data: { pdate: pdate, ptype: ptype, pnote: pnote, pinvid: pinvid}, public String save_it(String pdate, String ptype, Int64 pinvid, String pnote) { try { DateTime datenow = Convert.ToDateTime(pdate); using (var db = new dbsmsEntities()) { purchasepayment newdata = new purchasepayment(); newdata.date = datenow; newdata.description = ""; newdata.purchaseinvoiceid = pinvid; newdata.supplierid = db.hpurchaseinvoices.Find(pinvid).supplierid; newdata.projectid = Convert.ToInt64(Session["project"]); newdata.type = ptype; newdata.note = pnote; newdata.total = db.hpurchaseinvoices.Find(pinvid).grandtotal; newdata.number = db.hpurchaseinvoices.Find(pinvid).number; db.hpurchaseinvoices.Find(pinvid).status = 1; db.purchasepayments.Add(newdata); db.projects.Find(Convert.ToInt64(Session["project"])).status1.purchasepayment = 1; db.SaveChanges(); return(GlobalFunction.get_max_id("purchasepayment").ToString()); } } catch (Exception e) { return("fail"); } }
public string save_user(string userId, string userName, string userUserName, string userDesc) { string userPass = ""; using (var db = new dbsmsEntities()) { if (db.users.Select(x => x.username).Contains(userUserName)) { return("0"); } if (String.IsNullOrEmpty(userId)) { user data = new user(); data.name = userName; data.username = userUserName; userPass = userUserName + "123"; data.password = MD5.Hash(userPass); data.description = userDesc; data.status = 1; db.users.Add(data); } else { user data = db.users.Find(Convert.ToInt64(userId)); data.name = userName; data.username = userUserName; data.password = MD5.Hash(userPass); data.description = userDesc; } db.SaveChanges(); } return("1"); }
//data: { pdate: pdate, ptype: ptype, pnote: pnote, pinvid: pinvid}, public String save_it(String pdate, String ptype, Int64 pinvid, String pnote) { try { DateTime datenow = Convert.ToDateTime(pdate); using (var db = new dbsmsEntities()) { salespayment newdata = new salespayment(); newdata.date = datenow; newdata.description = ""; newdata.salesinvoiceid = pinvid; newdata.to = db.hsalesinvoices.Find(pinvid).customer.name + "\n" + db.hsalesinvoices.Find(pinvid).customer.address + "\n" + db.hsalesinvoices.Find(pinvid).customer.city + "\n" + db.hsalesinvoices.Find(pinvid).customer.phone; newdata.projectid = Convert.ToInt64(Session["project"]); newdata.type = ptype; newdata.note = pnote; newdata.total = db.hsalesinvoices.Find(pinvid).grandtotal; newdata.number = db.hsalesinvoices.Find(pinvid).number; db.hsalesinvoices.Find(pinvid).status = 1; db.salespayments.Add(newdata); db.projects.Find(Convert.ToInt64(Session["project"])).status1.salespayment = 1; db.SaveChanges(); return(GlobalFunction.get_max_id("salespayment").ToString()); } } catch (Exception e) { return("fail"); } }
public ActionResult save_customer(string custId, string custName, string custAddress, string custCity, string custPhone, string custDesc, int mode = 0) { using (var db = new dbsmsEntities()) { if (String.IsNullOrEmpty(custId)) { customer data = new customer(); data.name = custName; data.phone = custPhone; data.city = custCity; data.address = custAddress; data.description = custDesc; data.status = 1; db.customers.Add(data); } else { customer data = db.customers.Find(Convert.ToInt64(custId)); data.name = custName; data.address = custAddress; data.phone = custPhone; data.city = custCity; data.description = custDesc; } db.SaveChanges(); } TempData["success"] = "Your data has been saved."; if (mode != 0) { return(null); } return(RedirectToAction("Master_Customer", "Master")); }
public String save_all(string detail) { try { using (var db = new dbsmsEntities()) { Int64 projid = Convert.ToInt64(Session["project"]); List <findprice> deleted = db.projects.Find(projid).findprices.ToList(); if (deleted.Count > 0) { db.findprices.RemoveRange(deleted); } db.SaveChanges(); String[] res = detail.Split('ѥ'); for (int i = 0; i < res.Length - 1; i++) { String[] result = res[i].Split('Ё'); findprice data = new findprice(); data.supplierid = Convert.ToInt64(result[0]); data.address = ""; data.itemcategoryid = Convert.ToInt64(result[1]); data.itemdescription = result[2]; data.qty = Convert.ToInt64(result[3]); data.unitprice = Convert.ToInt64(result[4]); data.timeneeded = Convert.ToInt64(result[5]); data.description = result[6]; data.status = 1; data.projectid = Convert.ToInt64(Session["project"]); db.findprices.Add(data); } db.SaveChanges(); using (var db1 = new dbsmsEntities()) { db1.findprices.Find(GlobalFunction.get_max_id("findprices")).project.status1.findprices = 1; db1.SaveChanges(); return("success"); } } } catch (Exception e) { return("fail"); } }
public ActionResult FinishProject() { using (var db = new dbsmsEntities()) { Int64 id = Convert.ToInt64(Session["project"]); db.projects.Find(id).status = 1; db.SaveChanges(); } return(Redirect(Url.Action("Index", "Home"))); }
public String reset_pass(String userid) { using (var db = new dbsmsEntities()) { user data = db.users.Find(Convert.ToInt64(userid)); data.password = MD5.Hash(data.username + "123"); db.SaveChanges(); } return("reset ke username + 123"); }
public String save_all(String number, String date, long customerid, string to, string description, String projectName, string detail) { try { using (var db = new dbsmsEntities()) { status s = new status(); project p = new project(); p.status1 = s; p.name = projectName; p.status = 0; p.description = ""; db.projects.Add(p); db.SaveChanges(); Session["project"] = db.projects.Select(x => x.id).Max(); } DateTime datenow = Convert.ToDateTime(date); using (var db = new dbsmsEntities()) { hrfq newdata = new hrfq(); newdata.number = number; newdata.date = datenow; newdata.customerid = customerid; newdata.to = to; newdata.description = description; newdata.projectid = Convert.ToInt64(Session["project"]); db.hrfqs.Add(newdata); String[] res = detail.Split('ѥ'); for (int i = 0; i < res.Length - 1; i++) { String[] result = res[i].Split('Ё'); drfq data = new drfq(); data.itemcategoryid = Convert.ToInt64(result[0]); data.itemdescription = result[1]; data.qty = Convert.ToInt32(result[2]); data.unitprice = Convert.ToInt32(result[3]); data.subtotal = data.qty * data.unitprice; db.drfqs.Add(data); } db.SaveChanges(); using (var db1 = new dbsmsEntities()) { db1.hrfqs.Find(GlobalFunction.get_max_id("hrfq")).project.status1.rfq = 1; db1.hrfqs.Find(GlobalFunction.get_max_id("hrfq")).project.customerid = customerid; db1.SaveChanges(); return("success"); } } } catch (Exception e) { return("fail"); } }
public ActionResult delete_role(string roleId) { using (var db = new dbsmsEntities()) { role data = db.roles.Find(Convert.ToInt64(roleId)); db.users.ToList().ForEach(x => x.roles.Remove(data)); db.privileges.ToList().ForEach(x => x.roles.Remove(data)); db.roles.Remove(data); db.SaveChanges(); } TempData["success"] = "Your data has been deleted."; return(RedirectToAction("Index", "Role")); }
public ActionResult delete_category(string catId) { using (var db = new dbsmsEntities()) { if (!String.IsNullOrEmpty(catId)) { item_category data = db.item_category.Find(Convert.ToInt64(catId)); data.status = 0; } db.SaveChanges(); } TempData["success"] = "Your data has been deleted."; return(RedirectToAction("Master_Kategori", "Master")); }
public ActionResult delete_user(string userId) { using (var db = new dbsmsEntities()) { if (!String.IsNullOrEmpty(userId)) { user data = db.users.Find(Convert.ToInt64(userId)); data.status = 0; } db.SaveChanges(); } TempData["success"] = "Your data has been deleted."; return(RedirectToAction("Master_User", "Master")); }
//data: { pino: pino, pidate: pidate, poid: poid, desc: desc, detail: detail, disc:disc }, public String save_it(String pino, String pidate, Int64 poid, Int64 disc, String desc, String detail) { try { DateTime datenow = Convert.ToDateTime(pidate); using (var db = new dbsmsEntities()) { hpurchaseinvoice newdata = new hpurchaseinvoice(); newdata.date = datenow; newdata.description = desc; newdata.poid = poid; newdata.supplierid = db.hpoes.Find(poid).supplierid; newdata.projectid = Convert.ToInt64(Session["project"]); newdata.terms = "C.O.D"; newdata.number = pino; db.hpurchaseinvoices.Add(newdata); Int64 total = 0; String[] res = detail.Split('ѥ'); for (int i = 0; i < res.Length - 1; i++) { String[] result = res[i].Split('Ё'); dpurchaseinvoice data = new dpurchaseinvoice(); //detail += itemcatid + "Ё" + itemdescription + "Ё" + qty + "Ё" + unitprice; data.itemcategoryid = Convert.ToInt64(result[0]); data.itemdescription = result[1]; data.qty = Convert.ToInt32(result[2]); data.unitprice = Convert.ToInt32(result[3]); data.subtotal = data.qty * data.unitprice; total += data.subtotal; //data.penawaranid = GlobalFunction.get_max_id("hpenawaran"); db.dpurchaseinvoices.Add(data); } total -= db.hpoes.Find(poid).dp; newdata.total = total; newdata.diskon = disc; newdata.grandtotal = newdata.total - newdata.diskon; db.SaveChanges(); using (var db1 = new dbsmsEntities()) { db1.projects.Find(Convert.ToInt64(Session["project"])).status1.purchaseinvoice = 1; db1.SaveChanges(); return("success"); } } } catch (Exception e) { return("fail"); } }
public String edit_desc(Int64 projid, String desc) { try { using (var db = new dbsmsEntities()) { db.projects.Find(projid).description = desc; db.SaveChanges(); } return("success"); } catch { return("fail"); } }
public String delete_it(Int64 id) { try { using (var db = new dbsmsEntities()) { salespayment data = db.salespayments.Find(id); data.hsalesinvoice.status = 0; db.salespayments.Remove(data); db.SaveChanges(); return("success"); } } catch { return("fail"); } }
public ActionResult save_role(String param, String userid) { using (var db = new dbsmsEntities()) { user data = db.users.Find(Convert.ToInt64(userid)); db.roles.ToList().ForEach(x => x.users.Remove(data)); foreach (String item in param.Split('|')) { if (!String.IsNullOrEmpty(item)) { role rol = db.roles.Find(Convert.ToInt64(item)); data.roles.Add(rol); } } db.SaveChanges(); } return(RedirectToAction("Master_User", "Master")); }
public String delete_it(Int64 id) { try { using (var db = new dbsmsEntities()) { hreceiveitem data = db.hreceiveitems.Find(id); List <dreceiveitem> ddata = data.dreceiveitems.ToList(); db.dreceiveitems.RemoveRange(ddata); db.hreceiveitems.Remove(data); db.SaveChanges(); return("success"); } } catch { return("fail"); } }
public String delete_it(Int64 id) { try { using (var db = new dbsmsEntities()) { hsalesinvoice data = db.hsalesinvoices.Find(id); List <dsalesinvoice> ddata = data.dsalesinvoices.ToList(); db.dsalesinvoices.RemoveRange(ddata); db.hsalesinvoices.Remove(data); db.SaveChanges(); return("success"); } } catch { return("fail"); } }
public string change_password(string oldPassword, string newPassword) { using (var db = new dbsmsEntities()) { try { string pass = MD5.Hash(oldPassword); string username = Session["user"].ToString(); user user_ = (from u in db.users where u.password == pass && u.username == username select u).First(); user_.password = MD5.Hash(newPassword); db.SaveChanges(); return("1"); } catch (System.Exception e) { return("0"); } } }
public String save_it(String sjdate, String shipto, String desc, String detail) { try { DateTime datenow = Convert.ToDateTime(sjdate); using (var db = new dbsmsEntities()) { hsuratjalan newdata = new hsuratjalan(); newdata.date = datenow; newdata.description = desc; newdata.to = shipto; newdata.projectid = Convert.ToInt64(Session["project"]); newdata.number = GlobalFunction.generate_code("SJ"); db.hsuratjalans.Add(newdata); String[] res = detail.Split('ѥ'); for (int i = 0; i < res.Length - 1; i++) { String[] result = res[i].Split('Ё'); dsuratjalan data = new dsuratjalan(); //detail += itemcatid + "Ё" + itemdescription + "Ё" + qty; data.itemcategoryid = Convert.ToInt64(result[0]); data.itemdescription = result[1]; data.qty = Convert.ToInt32(result[2]); //data.penawaranid = GlobalFunction.get_max_id("hpenawaran"); db.dsuratjalans.Add(data); } db.SaveChanges(); using (var db1 = new dbsmsEntities()) { db1.projects.Find(Convert.ToInt64(Session["project"])).status1.suratjalan = 1; db1.SaveChanges(); return("success"); } } } catch (Exception e) { return("fail"); } }
public ActionResult save_role(string roleId, string roleName, string roleDesc) { using (var db = new dbsmsEntities()) { if (String.IsNullOrEmpty(roleId)) { role data = new role(); data.name = roleName; data.description = roleDesc; db.roles.Add(data); } else { role data = db.roles.Find(Convert.ToInt64(roleId)); data.name = roleName; data.description = roleDesc; } db.SaveChanges(); } TempData["success"] = "Your data has been saved."; return(RedirectToAction("Index", "Role")); }
public ActionResult save_category(string catId, string catName, string catDesc) { using (var db = new dbsmsEntities()) { if (String.IsNullOrEmpty(catId)) { item_category data = new item_category(); data.name = catName; data.description = catDesc; data.status = 1; db.item_category.Add(data); } else { item_category data = db.item_category.Find(Convert.ToInt64(catId)); data.name = catName; data.description = catDesc; } db.SaveChanges(); } TempData["success"] = "Your data has been saved."; return(RedirectToAction("Master_Kategori", "Master")); }
public ActionResult save_privilege(String param, String roleid) { int a = 0; using (var db = new dbsmsEntities()) { role data = db.roles.Find(Convert.ToInt64(roleid)); db.privileges.ToList().ForEach(x => x.roles.Remove(data)); foreach (String item in param.Split('$')) { if (!String.IsNullOrEmpty(item)) { String action = item.Split('|')[0]; String tablename = item.Split('|')[1]; privilege pr = (from p in db.privileges where p.action == action && p.tablename == tablename select p).First(); db.roles.Find(Convert.ToInt64(roleid)).privileges.Add(pr); } } db.SaveChanges(); } return(RedirectToAction("Index", "Role")); }
public String save_all(String quotedate, String quoteto, Int64 projectid, String desc, Int64 total, Int64 disc, Int64 grandtotal, String detail, Boolean edit = false) { try { DateTime datenow = Convert.ToDateTime(quotedate); using (var db = new dbsmsEntities()) { hpenawaran newdata = new hpenawaran(); if (edit) { newdata = db.projects.Find(projectid).hpenawarans.First(); } newdata.date = datenow; newdata.projectid = projectid; if (!edit) { newdata.number = GlobalFunction.generate_code("PNW"); } newdata.customerid = db.projects.Find(projectid).customer.id; newdata.to = quoteto; newdata.description = desc; newdata.disc = disc; newdata.total = total; newdata.grandtotal = grandtotal; if (!edit) { db.hpenawarans.Add(newdata); } if (edit) { List <dpenawaran> dpn = newdata.dpenawarans.ToList(); db.dpenawarans.RemoveRange(dpn); } String[] res = detail.Split('ѥ'); for (int i = 0; i < res.Length - 1; i++) { String[] result = res[i].Split('Ё'); dpenawaran data = new dpenawaran(); //itemcatid+"Ё"+itemdescription+"Ё"+suppid+"Ё"+qty+"Ё"+unitprice+"Ё"+subtotal data.itemcategoryid = Convert.ToInt64(result[0]); data.itemdescription = result[1]; data.supplierid = Convert.ToInt32(result[2]); data.qty = Convert.ToInt32(result[3]); data.unitprice = Convert.ToInt32(result[4]); data.subtotal = data.qty * data.unitprice; data.hpenawaran = newdata; //data.penawaranid = GlobalFunction.get_max_id("hpenawaran"); db.dpenawarans.Add(data); } db.SaveChanges(); using (var db1 = new dbsmsEntities()) { if (!edit) { db1.hpenawarans.Find(GlobalFunction.get_max_id("hpenawaran")).project.status1.penawaran = 1; } db1.SaveChanges(); return("success"); } } } catch (Exception e) { return("fail"); } }
public String save_it(String podate, Int64 poid, String expecteddate, String shipto, String terms, Int64 projectid, String desc, Int64 dp, Int64 discount, Int64 remainingpayment, String detail, Boolean edit = false) { try { DateTime datenow = Convert.ToDateTime(podate); DateTime datenow1 = Convert.ToDateTime(expecteddate); using (var db = new dbsmsEntities()) { hpo newdata = db.hpoes.Find(poid); newdata.date = datenow; newdata.expecteddate = datenow1; newdata.terms = terms; newdata.description = desc; newdata.dp = dp; newdata.discount = discount; newdata.grandtotal = remainingpayment; newdata.to = shipto; newdata.status = 1; db.SaveChanges(); if (dp > 0 && !edit) { using (var db1 = new dbsmsEntities()) { hpurchaseinvoice newdata1 = new hpurchaseinvoice(); newdata1.date = datenow; newdata1.number = GlobalFunction.generate_code("DP"); newdata1.projectid = projectid; newdata1.terms = terms; newdata1.supplierid = newdata.supplierid; newdata1.description = "Down payment untuk PO : " + newdata.number; newdata1.total = dp; newdata1.grandtotal = dp; newdata1.poid = poid; newdata1.diskon = 0; db1.hpurchaseinvoices.Add(newdata1); dpurchaseinvoice newdata2 = new dpurchaseinvoice(); newdata2.itemcategoryid = 2; newdata2.itemdescription = "Down Payment"; newdata2.qty = 1; newdata2.unitprice = dp; newdata2.subtotal = dp; db1.dpurchaseinvoices.Add(newdata2); db1.hpoes.Find(poid).project.status1.purchaseinvoice = 1; db1.SaveChanges(); } } using (var db1 = new dbsmsEntities()) { //purchasepayment pp = new purchasepayment(); //pp.projectid = projectid; //pp.purchaseinvoiceid = GlobalFunction.get_max_id("hpurchaseinvoice"); //pp.number = db1.hpurchaseinvoices.Find(GlobalFunction.get_max_id("hpurchaseinvoice")).number; //pp.date = datenow; //pp.supplierid = newdata.supplierid; //pp.total = dp; //pp.description = "Pembayaran DP untuk PO : " + newdata.number; //pp.type = terms; //pp.note = ""; //db1.purchasepayments.Add(pp); db1.hpoes.Find(poid).project.status1.purchaseorder = 1; db1.SaveChanges(); return("success"); } } } catch (Exception e) { return("fail"); } }
//data: { ridate: ridate, poid: poid, desc: desc, detail: detail }, public String save_it(String rinum, String ridate, Int64 poid, String desc, String detail) { try { DateTime datenow = Convert.ToDateTime(ridate); using (var db = new dbsmsEntities()) { hreceiveitem newdata = new hreceiveitem(); newdata.date = datenow; newdata.description = desc; newdata.poid = poid; newdata.supplierid = db.hpoes.Find(poid).supplierid; newdata.projectid = Convert.ToInt64(Session["project"]); newdata.number = rinum; db.hreceiveitems.Add(newdata); String[] res = detail.Split('ѥ'); for (int i = 0; i < res.Length - 1; i++) { String[] result = res[i].Split('Ё'); dreceiveitem data = new dreceiveitem(); //detail += itemcatid + "Ё" + itemdescription + "Ё" + qty; data.itemcategoryid = Convert.ToInt64(result[0]); data.itemdescription = result[1]; data.qty = Convert.ToInt32(result[2]); //data.penawaranid = GlobalFunction.get_max_id("hpenawaran"); db.dreceiveitems.Add(data); } db.SaveChanges(); using (var db1 = new dbsmsEntities()) { hpo po_ = db1.hpoes.Find(poid); bool penuh = true; foreach (dpo item in po_.dpoes.ToList()) { Int64 total = 0; foreach (hreceiveitem item2 in db1.hreceiveitems.Where(x => x.poid == poid)) { foreach (dreceiveitem item3 in item2.dreceiveitems.Where(x => x.itemcategoryid == item.itemcategoryid && x.itemdescription == item.itemdescription)) { total += item3.qty; } } if (total != item.qty) { penuh = false; } } if (penuh) { po_.status = 2; } db1.projects.Find(Convert.ToInt64(Session["project"])).status1.receiveitem = 1; db1.SaveChanges(); return("success"); } } } catch (Exception e) { return("fail"); } }
public String delete_project(Int64 projid) { try { using (var db = new dbsmsEntities()) { project p = db.projects.Find(projid); List <salespayment> item1 = p.salespayments.ToList(); db.salespayments.RemoveRange(item1); List <hsalesinvoice> item2 = p.hsalesinvoices.ToList(); foreach (hsalesinvoice item in item2) { db.dsalesinvoices.RemoveRange(item.dsalesinvoices); } db.hsalesinvoices.RemoveRange(item2); List <hsuratjalan> item3 = p.hsuratjalans.ToList(); foreach (hsuratjalan item in p.hsuratjalans) { db.dsuratjalans.RemoveRange(item.dsuratjalans); } db.hsuratjalans.RemoveRange(item3); List <purchasepayment> item4 = p.purchasepayments.ToList(); db.purchasepayments.RemoveRange(item4); List <hpurchaseinvoice> item5 = p.hpurchaseinvoices.ToList(); foreach (hpurchaseinvoice item in p.hpurchaseinvoices) { db.dpurchaseinvoices.RemoveRange(item.dpurchaseinvoices); } db.hpurchaseinvoices.RemoveRange(item5); List <hreceiveitem> item6 = p.hreceiveitems.ToList(); foreach (hreceiveitem item in p.hreceiveitems) { db.dreceiveitems.RemoveRange(item.dreceiveitems); } db.hreceiveitems.RemoveRange(item6); List <hpo> item7 = p.hpoes.ToList(); foreach (hpo item in p.hpoes) { db.dpoes.RemoveRange(item.dpoes); } db.hpoes.RemoveRange(item7); List <hsalesorder> item8 = p.hsalesorders.ToList(); foreach (hsalesorder item in p.hsalesorders) { db.dsalesorders.RemoveRange(item.dsalesorders); } db.hsalesorders.RemoveRange(item8); List <hpenawaran> item9 = p.hpenawarans.ToList(); foreach (hpenawaran item in p.hpenawarans) { db.dpenawarans.RemoveRange(item.dpenawarans); } db.hpenawarans.RemoveRange(item9); List <findprice> item10 = p.findprices.ToList(); db.findprices.RemoveRange(item10); List <hrfq> item11 = p.hrfqs.ToList(); foreach (hrfq item in p.hrfqs) { db.drfqs.RemoveRange(item.drfqs); } db.hrfqs.RemoveRange(item11); //deletenote db.rfqnotes.RemoveRange(p.rfqnotes); db.findpricesnotes.RemoveRange(p.findpricesnotes); db.penawarannotes.RemoveRange(p.penawarannotes); db.salesordernotes.RemoveRange(p.salesordernotes); db.ponotes.RemoveRange(p.ponotes); db.receiveitemnotes.RemoveRange(p.receiveitemnotes); db.purchaseinvoicenotes.RemoveRange(p.purchaseinvoicenotes); db.purchasepaymentnotes.RemoveRange(p.purchasepaymentnotes); db.suratjalannotes.RemoveRange(p.suratjalannotes); db.salesinvoicenotes.RemoveRange(p.salesinvoicenotes); db.salespaymentnotes.RemoveRange(p.salespaymentnotes); //endofdeletenote db.projects.Remove(p); db.SaveChanges(); } return("success"); } catch (Exception e) { return("fail"); throw; } }
public String repeat_project(Int64 projid, String projname) { try { using (var db = new dbsmsEntities()) { project p_lama = db.projects.Find(projid); hrfq hrfq_lama = p_lama.hrfqs.First(); List <drfq> drfq_lama = hrfq_lama.drfqs.ToList(); List <findprice> findprice_lama = p_lama.findprices.ToList(); hpenawaran hpenawaran_lama = p_lama.hpenawarans.First(); List <dpenawaran> dpenawaran_lama = hpenawaran_lama.dpenawarans.ToList(); status s = new status(); project p_baru = new project(); p_baru.status1 = s; p_baru.name = projname; p_baru.status = 0; p_baru.customer = p_lama.customer; p_baru.description = ""; db.projects.Add(p_baru); hrfq hrfq_baru = new hrfq(); hrfq_baru.customer = hrfq_lama.customer; hrfq_baru.date = DateTime.Now; hrfq_baru.description = ""; hrfq_baru.to = hrfq_lama.to; hrfq_baru.description = hrfq_lama.description; hrfq_baru.project = p_baru; db.hrfqs.Add(hrfq_baru); drfq_lama.ForEach(x => { drfq drfq_baru = new drfq(); drfq_baru.hrfq = hrfq_baru; drfq_baru.itemcategoryid = x.itemcategoryid; drfq_baru.itemdescription = x.itemdescription; drfq_baru.qty = x.qty; drfq_baru.subtotal = x.subtotal; drfq_baru.unitprice = x.unitprice; db.drfqs.Add(drfq_baru); }); findprice_lama.ForEach(x => { findprice findprice_baru = new findprice(); findprice_baru.address = x.address; findprice_baru.description = x.description; findprice_baru.itemdescription = x.itemdescription; findprice_baru.project = p_baru; findprice_baru.qty = x.qty; findprice_baru.status = x.status; findprice_baru.supplier = x.supplier; findprice_baru.timeneeded = x.timeneeded; findprice_baru.unitprice = x.unitprice; db.findprices.Add(findprice_baru); }); hpenawaran hpenawaran_baru = new hpenawaran(); hpenawaran_baru.customer = hpenawaran_lama.customer; hpenawaran_baru.date = DateTime.Now; hpenawaran_baru.description = ""; hpenawaran_baru.to = hpenawaran_lama.to; hpenawaran_baru.description = hpenawaran_lama.description; hpenawaran_baru.project = p_baru; hpenawaran_baru.disc = hpenawaran_lama.disc; hpenawaran_baru.grandtotal = hpenawaran_lama.grandtotal; hpenawaran_baru.number = GlobalFunction.generate_code("PNW"); hpenawaran_baru.to = hpenawaran_lama.to; hpenawaran_baru.total = hpenawaran_lama.total; db.hpenawarans.Add(hpenawaran_baru); dpenawaran_lama.ForEach(x => { dpenawaran dpenawaran_baru = new dpenawaran(); dpenawaran_baru.hpenawaran = hpenawaran_baru; dpenawaran_baru.itemcategoryid = x.itemcategoryid; dpenawaran_baru.itemdescription = x.itemdescription; dpenawaran_baru.qty = x.qty; dpenawaran_baru.subtotal = x.subtotal; dpenawaran_baru.unitprice = x.unitprice; dpenawaran_baru.supplier = x.supplier; db.dpenawarans.Add(dpenawaran_baru); }); p_baru.status1.rfq = 1; p_baru.status1.findprices = 1; p_baru.status1.penawaran = 1; db.SaveChanges(); } Int64 id = GlobalFunction.get_max_id("project"); Session["project"] = id; return("success"); } catch { return("fail"); } }
public String save_all(String sodate, String expecteddate, String designdate, String terms, Int64 tcustomer, String usedesign, Int64 projectid, String desc, Int64 total, Int64 dp, Int64 remainingpayment, String detail, Boolean edit = false) { try { DateTime datenow = Convert.ToDateTime(sodate); DateTime datenow1 = Convert.ToDateTime(expecteddate); DateTime datenow2 = Convert.ToDateTime(designdate); String newSOnum = GlobalFunction.generate_code("SO"); using (var db = new dbsmsEntities()) { hsalesorder newdata = new hsalesorder(); if (edit) { newdata = db.projects.Find(projectid).hsalesorders.First(); } newdata.date = datenow; newdata.expecteddate = datenow1; if (usedesign == "true") { newdata.designdate = datenow2; } else { newdata.designdate = null; } newdata.terms = terms; newdata.customerid = tcustomer; newdata.projectid = projectid; newdata.description = desc; if (!edit) { newdata.number = newSOnum; } newdata.dp = dp; newdata.total = total; newdata.grandtotal = remainingpayment; if (!edit) { db.hsalesorders.Add(newdata); } if (edit) { List <dsalesorder> dpn = newdata.dsalesorders.ToList(); db.dsalesorders.RemoveRange(dpn); } String[] res = detail.Split('ѥ'); for (int i = 0; i < res.Length - 1; i++) { String[] result = res[i].Split('Ё'); dsalesorder data = new dsalesorder(); //itemcatid+"Ё"+itemdescription+"Ё"+qty+"Ё"+unitprice+"Ё"+subtotal data.itemcategoryid = Convert.ToInt64(result[0]); data.itemdescription = result[1]; data.qty = Convert.ToInt32(result[2]); data.unitprice = Convert.ToInt32(result[3]); data.subtotal = data.qty * data.unitprice; //data.penawaranid = GlobalFunction.get_max_id("hpenawaran"); if (edit) { data.hsalesorder = newdata; } db.dsalesorders.Add(data); } db.SaveChanges(); if (edit) { return("success"); } if (dp > 0) { using (var db1 = new dbsmsEntities()) { hsalesinvoice newdata1 = new hsalesinvoice(); newdata1.date = datenow; newdata1.number = GlobalFunction.generate_code("INV"); newdata1.projectid = projectid; newdata1.terms = terms; newdata1.customerid = tcustomer; newdata1.description = "Down payment untuk SO : " + newSOnum; newdata1.total = dp; newdata1.grandtotal = dp; db1.hsalesinvoices.Add(newdata1); dsalesinvoice newdata2 = new dsalesinvoice(); newdata2.itemcategoryid = 2; newdata2.itemdescription = "Down Payment"; newdata2.qty = 1; newdata2.unitprice = dp; newdata2.subtotal = dp; db1.dsalesinvoices.Add(newdata2); db1.SaveChanges(); using (var db2 = new dbsmsEntities()) { db2.hsalesinvoices.Find(GlobalFunction.get_max_id("hsalesinvoice")).project.status1.salesinvoice = 1; db2.SaveChanges(); } } } using (var db1 = new dbsmsEntities()) { foreach (Int64 item in db.projects.Find(Convert.ToInt64(Session["project"])).hpenawarans.First().dpenawarans.Select(x => x.supplierid).Distinct()) { String newponumb = GlobalFunction.generate_code("PO"); Int64 total_ = 0; hpo newhpo = new hpo(); newhpo.date = datenow; newhpo.projectid = Convert.ToInt64(Session["project"]); newhpo.number = newponumb; newhpo.supplierid = item; newhpo.terms = "C.O.D"; newhpo.to = ""; db1.hpoes.Add(newhpo); Int64 maxday = 0; foreach (dpenawaran item2 in db.projects.Find(Convert.ToInt64(Session["project"])).hpenawarans.First().dpenawarans.Where(x => x.supplierid == item)) { dpo newdpo = new dpo(); newdpo.itemcategoryid = item2.itemcategoryid; newdpo.itemdescription = item2.itemdescription; newdpo.qty = item2.qty; newdpo.unitprice = item2.hpenawaran.project.findprices.Where(x => x.supplierid == item && x.itemdescription == item2.itemdescription).First().unitprice; newdpo.subtotal = newdpo.qty * newdpo.unitprice; if (item2.hpenawaran.project.findprices.Where(x => x.supplierid == item && item2.itemdescription == x.itemdescription).First().timeneeded > maxday) { maxday = item2.hpenawaran.project.findprices.Where(x => x.supplierid == item && item2.itemdescription == x.itemdescription).First().timeneeded; } total_ += newdpo.subtotal; db1.dpoes.Add(newdpo); } newhpo.total = total_; newhpo.dp = 0; newhpo.discount = 0; newhpo.grandtotal = total_; newhpo.expecteddate = datenow.AddDays(maxday); db1.SaveChanges(); } db1.hsalesorders.Find(GlobalFunction.get_max_id("hsalesorder")).project.status1.salesorder = 1; db1.SaveChanges(); return("success"); } } } catch (Exception e) { return("fail"); } }
public String add_note(String text, String controller) { try { using (var db = new dbsmsEntities()) { if (controller.ToLower() == "rfq") { rfqnote data = new rfqnote(); data.projectid = Convert.ToInt64(Session["project"]); data.username = Session["user"].ToString(); data.text = text; data.date = DateTime.Now; db.rfqnotes.Add(data); } else if (controller.ToLower() == "findprices") { findpricesnote data = new findpricesnote(); data.projectid = Convert.ToInt64(Session["project"]); data.username = Session["user"].ToString(); data.text = text; data.date = DateTime.Now; db.findpricesnotes.Add(data); } else if (controller.ToLower() == "penawaran") { penawarannote data = new penawarannote(); data.projectid = Convert.ToInt64(Session["project"]); data.username = Session["user"].ToString(); data.text = text; data.date = DateTime.Now; db.penawarannotes.Add(data); } else if (controller.ToLower() == "salesorder") { salesordernote data = new salesordernote(); data.projectid = Convert.ToInt64(Session["project"]); data.username = Session["user"].ToString(); data.text = text; data.date = DateTime.Now; db.salesordernotes.Add(data); } else if (controller.ToLower() == "purchaseorder") { ponote data = new ponote(); data.projectid = Convert.ToInt64(Session["project"]); data.username = Session["user"].ToString(); data.text = text; data.date = DateTime.Now; db.ponotes.Add(data); } else if (controller.ToLower() == "receiveitem") { receiveitemnote data = new receiveitemnote(); data.projectid = Convert.ToInt64(Session["project"]); data.username = Session["user"].ToString(); data.text = text; data.date = DateTime.Now; db.receiveitemnotes.Add(data); } else if (controller.ToLower() == "purchaseinvoice") { purchaseinvoicenote data = new purchaseinvoicenote(); data.projectid = Convert.ToInt64(Session["project"]); data.username = Session["user"].ToString(); data.text = text; data.date = DateTime.Now; db.purchaseinvoicenotes.Add(data); } else if (controller.ToLower() == "purchasepayment") { purchasepaymentnote data = new purchasepaymentnote(); data.projectid = Convert.ToInt64(Session["project"]); data.username = Session["user"].ToString(); data.text = text; data.date = DateTime.Now; db.purchasepaymentnotes.Add(data); } else if (controller.ToLower() == "suratjalan") { suratjalannote data = new suratjalannote(); data.projectid = Convert.ToInt64(Session["project"]); data.username = Session["user"].ToString(); data.text = text; data.date = DateTime.Now; db.suratjalannotes.Add(data); } else if (controller.ToLower() == "salesinvoice") { salesinvoicenote data = new salesinvoicenote(); data.projectid = Convert.ToInt64(Session["project"]); data.username = Session["user"].ToString(); data.text = text; data.date = DateTime.Now; db.salesinvoicenotes.Add(data); } else if (controller.ToLower() == "salespayment") { salespaymentnote data = new salespaymentnote(); data.projectid = Convert.ToInt64(Session["project"]); data.username = Session["user"].ToString(); data.text = text; data.date = DateTime.Now; db.salespaymentnotes.Add(data); } db.SaveChanges(); return("success"); } } catch (Exception) { return("fail"); } }