Ejemplo n.º 1
0
        public ActionResult Detail(string id)
        {
            MD_IMPORTDETAIL model = new MD_IMPORTDETAIL();

            if (!string.IsNullOrEmpty(id))
            {
                var result = APIHelper.CallAPI <JsonResultObject <List <MD_IMPORTDETAIL> > >("importdetail/getdetail", new
                {
                    id = id
                });
                if (result.IsOk)
                {
                    model = result.dataObj.FirstOrDefault();
                }
            }
            ImportFileDetailViewModel resultView = new ImportFileDetailViewModel();

            resultView = ModelHelper.ConvertHelper.Current.ConvertObjToObj <ImportFileDetailViewModel, MD_IMPORTDETAIL>(model);
            resultView.AutoInitLink();
            return(View(resultView));
        }
Ejemplo n.º 2
0
        public JsonResult Update(ImportFileDetailViewModel info)
        {
            info.UPDATEDDATE = DateTime.Now;
            info.UPDATEDUSER = LoginUser.Current.USERNAME;
            MD_IMPORTDETAIL detail     = info.GetDetailImportFile();
            var             resultJson = APIHelper.CallAPI <JsonResultData>("importdetail/Update", new
            {
                data = detail
            });

            if (!resultJson.IsOk)
            {
                return(Json(resultJson, JsonRequestBehavior.AllowGet));
            }
            var lstCnt = info.GetImportContainer();

            foreach (var cnt in lstCnt)
            {
                if (cnt.ID != 0)
                {
                    resultJson = APIHelper.CallAPI <JsonResultData>("importpkl/Update", new
                    {
                        data = cnt
                    });
                    if (!resultJson.IsOk)
                    {
                        return(Json(resultJson, JsonRequestBehavior.AllowGet));
                    }
                }
                else
                {
                    resultJson = APIHelper.CallAPI <JsonResultData>("importpkl/Insert", new
                    {
                        data = cnt
                    });
                    if (!resultJson.IsOk)
                    {
                        return(Json(resultJson, JsonRequestBehavior.AllowGet));
                    }
                }
            }
            var lstPallet = info.GetImportPallet();

            foreach (var pallet in lstPallet)
            {
                var searchcontract = APIHelper.CallAPI <JsonResultObject <List <MD_IMPORTCONTRACT> > >("importcontract/getdetailbycode", new
                {
                    code = detail.IMPORTCONTRACTCODE
                });
                if (!searchcontract.IsOk)
                {
                    return(Json(searchcontract, JsonRequestBehavior.AllowGet));
                }
                var contract     = searchcontract.dataObj.First();
                var fullcontract = new ImpContractEditViewModel(contract);
                var supplier     = fullcontract.SupplierDetail.SUPPLIERNAME;
                var material     = APIHelper.CallAPI <JsonResultObject <List <MD_MATERIAL> > >("material/getdetail", new
                {
                    id = pallet.MATERIALID
                });
                if (!material.IsOk)
                {
                    return(Json(material, JsonRequestBehavior.AllowGet));
                }
                var materialName = material.dataObj != null?material.dataObj.FirstOrDefault().NAME : string.Empty;

                var submaterialName = string.Empty;
                if (pallet.SUBMATERIALID.HasValue)
                {
                    var submaterial = APIHelper.CallAPI <JsonResultObject <List <MD_SUBMATERIAL> > >("submaterial/getdetail", new
                    {
                        id = pallet.SUBMATERIALID.Value
                    });
                    if (!submaterial.IsOk)
                    {
                        return(Json(submaterial, JsonRequestBehavior.AllowGet));
                    }
                    submaterialName = submaterial.dataObj != null?submaterial.dataObj.FirstOrDefault().NAME : string.Empty;
                }
                string Origin  = string.Empty;
                var    Sorigin = fullcontract.ItemList.Where(x => x.MATERIALID == pallet.MATERIALID && pallet.SUBMATERIALID.HasValue ? pallet.SUBMATERIALID.Value == x.SUBMATERIALID.Value : !x.SUBMATERIALID.HasValue);
                if (Sorigin.Count() > 0)
                {
                    Origin = Sorigin.First().ORIGIN;
                }
                var    fullNameMaterial = materialName + (string.IsNullOrEmpty(submaterialName) ? "" : " " + submaterialName);
                string objectSerialize  = string.Format("LAMIPEL ERP\nMaterial:{5}\nPallet No:{0}\nFile No:{1}\nSupplier:{2}\nContract No:{3}\nInvoice PKL:{4}\nContainer:{6}\nPCS:{7}\nNW:{8}\nSQFT:{9}\nSAVG:{10}\nWAVG:{11}", string.IsNullOrEmpty(pallet.PALLETDONECODE) ? "" : pallet.PALLETDONECODE, detail.IMPFILE, supplier, contract.IMPORTCODE, detail.INVOICE, fullNameMaterial, pallet.IMPORTPKL, pallet.PCS, pallet.NW, pallet.SQFT, pallet.SAVG, pallet.WAVG);
                pallet.SCANCODE = Barcode.Current.CreateQRString(objectSerialize);
                List <string> dataprint = new List <string>();
                dataprint.Add(string.IsNullOrEmpty(pallet.PALLETDONECODE) ? "" : pallet.PALLETDONECODE);//dataprint.Add(pallet.NAME);
                dataprint.Add(materialName);
                dataprint.Add(submaterialName);
                dataprint.Add(pallet.PCS.HasValue ? pallet.PCS.Value.ToString("#,##0") : "0");
                dataprint.Add(pallet.NW.HasValue ? pallet.NW.Value.ToString("#,##0") : "0");
                dataprint.Add(lstCnt.Where(x => x.PKLNAME == pallet.IMPORTPKL).First().PKLIDENTITY); //dataprint.Add(pallet.WAVG.HasValue ? pallet.WAVG.Value.ToString("#,##0") : "0");
                dataprint.Add(pallet.SQFT.HasValue ? pallet.SQFT.Value.ToString("#,##0") : "0");
                dataprint.Add(Origin);                                                               //origin
                dataprint.Add(info.ISLWG ? "YES" : "NO");                                            //lwg
                dataprint.Add(pallet.SCANCODE);
                var cnt = lstCnt.Where(x => x.PKLNAME == pallet.IMPORTPKL && x.IMPFILE == detail.IMPFILE);
                dataprint.Add(cnt != null && cnt.Count() > 0 ? cnt.First().PKLDONECODE : ""); //dataprint.Add(pallet.IMPORTPKL);
                dataprint.Add(supplier.Length > 15 ? supplier.Substring(0, 15) : supplier);
                pallet.TEMPLATEPRINT = BarcodeHelper.XMLHelper.Current.BuilResouce("ImportLabelPrint", dataprint.ToArray());
                if (pallet.ID == 0)
                {
                    pallet.CREATEDDATE = DateTime.Now;
                    pallet.CREATEDUSER = LoginUser.Current.USERNAME;
                    resultJson         = APIHelper.CallAPI <JsonResultData>("importpallet/Insert", new
                    {
                        data = pallet
                    });
                    if (!resultJson.IsOk)
                    {
                        return(Json(resultJson, JsonRequestBehavior.AllowGet));
                    }
                }
                else
                {
                    pallet.UPDATEDDATE = DateTime.Now;
                    pallet.UPDATEDUSER = LoginUser.Current.USERNAME;
                    resultJson         = APIHelper.CallAPI <JsonResultData>("importpallet/Update", new
                    {
                        data = pallet
                    });
                    if (!resultJson.IsOk)
                    {
                        return(Json(resultJson, JsonRequestBehavior.AllowGet));
                    }
                }
            }
            return(Json(resultJson, JsonRequestBehavior.AllowGet));
        }