/// <summary> /// Simpan model ke SPP dengan PO yang ada di multiple PO /// </summary> /// <param name="model"></param> private void SavePo(MultiplePrint model) { try { foreach (string item in model.multiple_po) { string[] splitString = item.Split(' '); string getPo = splitString[0]; int getSppId = Int32.Parse(splitString[3]); SppDashboard sd = db.sppData.FirstOrDefault(f => f.spp_id == getSppId); if (sd != null) { //SppDashboard nsd = new SppDashboard(); sd.spp_number = model.spp_number; sd.spp_date = model.spp_date; sd.address = model.address; sd.npwp = model.npwp; sd.bank_name = model.bank_name; sd.bill_number = model.bill_number; sd.bill_owner = model.bill_owner; sd.kabag_from = model.kabag_from; sd.kabag_from_name = model.kabag_from_name; sd.kabag_from_nik = model.kabag_from_nik; sd.kabag_accounting_name = model.kabag_accounting_name; sd.updated_at = DateTime.Now; //db.Entry(sd).CurrentValues.SetValues(nsd); db.Entry(sd).State = EntityState.Modified; } } db.SaveChanges(); } catch (Exception e) { Log.Error(e); } }
public ActionResult MultiplePrint(MultiplePrint model) { try { model.invoice_number = new List <InvoiceFormat>(); model.payment_for = new List <string>(); model.another = new List <string>(); model.job_code_x = new List <string>(); string[] attachs = new string[] { "false", "false", "false", "false", "false", "false", "false", "false", "false", "false", "false", "false", "false" }; double price = 0; string firstPo = null; if (model.multiple_po == null) { return(View()); } // START NEW List <string> listIdSpp = new List <string>(); foreach (string item in model.multiple_po) { string[] splitString = item.Split(' '); string getSppId = splitString[3]; listIdSpp.Add(getSppId); } string idString = string.Join(",", listIdSpp); string query = "SELECT DISTINCT s.spp_id, ( SELECT job_code FROM len_enq_dpb WHERE dpb = z.dpb LIMIT 1 ) AS job_code, ( SELECT job_code_t FROM len_enq_dpb WHERE dpb = z.dpb LIMIT 1 ) AS job_code_t, s.po, s.supplier, s.address, s.npwp, s.invoice_number, s.bank_name, s.bill_number, s.bill_owner, s.payment_for, s.another, s.attachment, s.kabag_from, s.kabag_from_name, s.kabag_from_nik, s.kabag_accounting_name FROM len_spp s JOIN len_enq_spph z ON z.po = s.po WHERE s.spp_id IN (" + idString + ");"; List <NewMultiPrint> newMulti = new List <NewMultiPrint>(); var newModel = db.Database.SqlQuery <NewMultiPrint>(query); if (newModel != null) { newMulti = newModel.ToList(); } if (newMulti.Count() > 0) { foreach (var item in newMulti) { // invoice list if (item.invoice_number != null) { JavaScriptSerializer js = new JavaScriptSerializer(); InvoiceFormat[] invoices = js.Deserialize <InvoiceFormat[]>(item.invoice_number); if (invoices.Count() > 0) { foreach (var invoice in invoices) { model.invoice_number.Add(invoice); price = price + invoice.total; } } } // untuk pembayaran if (item.payment_for != null) { model.payment_for.Add(item.payment_for); } // attachment if (item.attachment != null) { //attachs.Add(sd.attachment); bool[] boolString = Array.ConvertAll(item.attachment.Split(','), bool.Parse); for (int i = 0; i < boolString.Count(); i++) { if (boolString[i]) { attachs[i] = "true"; } } model.attachment = string.Join(",", attachs); } // lain lain if (item.another != null) { model.another.Add(item.another); } // job code dan job code t if (item.job_code != null && item.job_code_t != null) { model.job_code_x.Add(item.job_code + " - " + item.job_code_t); } } } // END NEW // START OLD //foreach (string item in model.multiple_po) //{ // string[] splitString = item.Split(' '); // string getPo = splitString[0]; // int getSppId = Int32.Parse(splitString[3]); // if(firstPo == null) // { // firstPo = getPo; // } // SppDashboard sd = db.sppData.FirstOrDefault(f => f.spp_id == getSppId); // if (sd != null) // { // // invoice list // if (sd.invoice_number != null) // { // JavaScriptSerializer js = new JavaScriptSerializer(); // InvoiceFormat[] invoices = js.Deserialize<InvoiceFormat[]>(sd.invoice_number); // if (invoices.Count() > 0) // { // foreach (var invoice in invoices) // { // model.invoice_number.Add(invoice); // price = price + invoice.total; // } // } // } // // untuk pembayaran // if (sd.payment_for != null) // { // model.payment_for.Add(sd.payment_for); // } // // attachment // if (sd.attachment != null) // { // //attachs.Add(sd.attachment); // bool[] boolString = Array.ConvertAll(sd.attachment.Split(','), bool.Parse); // for (int i = 0; i < boolString.Count(); i++) // { // if (boolString[i]) // { // attachs[i] = "true"; // } // } // model.attachment = string.Join(",", attachs); // } // // lain lain // if (sd.another != null) // { // model.another.Add(sd.another); // } // // job code dan job code t // var getDpb = // from basis in db.dbSpph // join dpb in db.dbDpb on basis.dpb equals dpb.dpb // where basis.po == getPo // select new { jobcode = dpb.job_code, jobcodet = dpb.job_code_t }; // var firstData = getDpb.FirstOrDefault(); // if (firstData != null) // { // if (firstData.jobcode != null && firstData.jobcodet != null) // { // model.job_code_x.Add(firstData.jobcode + " - " + firstData.jobcodet); // } // } // } //} // END OLD SavePo(model); ViewBag.total = price.ConvertToDot(); ViewBag.intWord = price.ToText(); //Session["multimodel"] = model; //Session["total"] = price; //Session["intWord"] = price.ToText(); model.total = price; model.intWord = price.ToText(); var modelx = new JavaScriptSerializer().Serialize(model); if (model.state == 2) { return(RedirectToAction("PDFMultiPO", new { modelx = modelx })); } else if (model.state == 3) { string redPo = firstPo; return(RedirectToAction("SPPBoard", "Po", new { po = redPo })); } else { Session["modelxx"] = modelx; //return RedirectToAction("NewMultiplePrint", new { modelx = modelx }); return(RedirectToAction("NewMultiplePrint")); } } catch (Exception e) { Log.Error(e); return(View()); } //return View(model); }