Exemple #1
0
        public ActionResult SPPForm(string po, int?spp)
        {
            try
            {
                ViewBag.useAjax       = true;
                ViewBag.useDatePicker = true;
                ViewBag.useIcheck     = true;
                ViewBag.po            = po;
                ViewBag.supplier      = "";
                ViewBag.address       = "";
                ViewBag.npwp          = "";
                ViewBag.billNumber    = "";
                ViewBag.cur           = "";
                if (po != null && po != "")
                {
                    PoTransactions pt = new PoTransactions(po);
                    //var poOptions = db.sppData.Select(s => s.po).ToList();
                    generatePaymentDropDown(false);
                    SppDashboard model        = new SppDashboard();
                    string       supplier     = pt.getSupplier();
                    string[]     supplierInfo = pt.getSupplierInfo();
                    if (supplier != null)
                    {
                        ViewBag.supplier = supplier;
                    }
                    model.spp_date = DateTime.Now;
                    var cur = db.dbPoProduct.FirstOrDefault(f => f.po == po);
                    if (cur != null)
                    {
                        try
                        {
                            ViewBag.cur = cur.cur;
                        }
                        catch (ArgumentNullException)
                        {
                            ViewBag.cur = "0";
                        }
                    }

                    List <string> poOptions = pt.getMultiplePo(ViewBag.supplier);
                    ViewBag.options = poOptions;

                    if (spp > 0)
                    {
                        model = pt.getSpp(spp);
                        if (model != null)
                        {
                            if (model.spp_date == null || model.spp_date == DateTime.MinValue)
                            {
                                model.spp_date = DateTime.Now;
                            }
                            if (supplierInfo != null && supplierInfo.Count() > 0)
                            {
                                model.address     = model.address != null ? model.address : supplierInfo[1];
                                model.npwp        = model.npwp != null ? model.npwp : supplierInfo[2];
                                model.bill_number = model.bill_number != null ? model.bill_number : supplierInfo[3];
                            }
                            ViewBag.attachmentOptions = model.attachment;

                            JavaScriptSerializer js       = new JavaScriptSerializer();
                            InvoiceFormat[]      invoices = js.Deserialize <InvoiceFormat[]>(model.invoice_number);
                            if (invoices.Count() > 0)
                            {
                                foreach (var invoice in invoices)
                                {
                                    model.invoice_num   = invoice.number;
                                    model.invoice_date  = invoice.date;
                                    model.invoice_value = invoice.total;
                                }
                            }

                            return(View(model));
                        }
                        ViewBag.noData = true;
                        return(View());
                    }
                    else
                    {
                        if (supplierInfo != null && supplierInfo.Count() > 0)
                        {
                            model.address     = model.address != null ? model.address : supplierInfo[1];
                            model.npwp        = model.npwp != null ? model.npwp : supplierInfo[2];
                            model.bill_number = model.bill_number != null ? model.bill_number : supplierInfo[3];
                        }
                    }
                    return(View(model));
                }
                ViewBag.noData = true;
                return(View());
            }
            catch (Exception e)
            {
                Log.Error(e);
                ViewBag.useAjax       = true;
                ViewBag.useDatePicker = true;
                ViewBag.useIcheck     = true;
                ViewBag.po            = po;
                ViewBag.cur           = "";
                ViewBag.supplier      = "";
                ViewBag.address       = "";
                ViewBag.npwp          = "";
                ViewBag.billNumber    = "";
                ViewBag.noData        = true;
                return(View());
            }
        }