Exemplo n.º 1
0
 //sidate: sidate, terms:terms, disc:disc, desc: desc, detail: detail
 public String save_it(String sidate, String terms, Int64 disc, String desc, String detail)
 {
     try
     {
         DateTime datenow = Convert.ToDateTime(sidate);
         using (var db = new dbsmsEntities())
         {
             hsalesinvoice newdata = new hsalesinvoice();
             newdata.date        = datenow;
             newdata.description = desc;
             newdata.terms       = terms;
             newdata.projectid   = Convert.ToInt64(Session["project"]);
             newdata.customerid  = db.projects.Find(Convert.ToInt64(Session["project"])).hsalesorders.First().customerid;
             newdata.number      = GlobalFunction.generate_code("INV");
             db.hsalesinvoices.Add(newdata);
             Int64    total = 0;
             String[] res   = detail.Split('ѥ');
             for (int i = 0; i < res.Length - 1; i++)
             {
                 String[]      result = res[i].Split('Ё');
                 dsalesinvoice data   = new dsalesinvoice();
                 //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.dsalesinvoices.Add(data);
             }
             total             -= db.projects.Find(Convert.ToInt64(Session["project"])).hsalesorders.First().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.salesinvoice = 1;
                 db1.SaveChanges();
                 return("success");
             }
         }
     }
     catch (Exception e)
     {
         return("fail");
     }
 }
Exemplo n.º 2
0
 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");
     }
 }