Beispiel #1
0
        public HttpResponseMessage SaveUpdatePOMasterNdetails(object[] data)
        {
            PurchasePOMaster        itemMaster  = JsonConvert.DeserializeObject <PurchasePOMaster>(data[0].ToString());
            List <PurchasePODetail> itemDetails = JsonConvert.DeserializeObject <List <PurchasePODetail> >(data[1].ToString());
            int       menuID    = Convert.ToInt16(data[2]);
            ArrayList fileNames = JsonConvert.DeserializeObject <ArrayList>(data[3].ToString());
            List <vmTermsCondition> termslist = JsonConvert.DeserializeObject <List <vmTermsCondition> >(data[4].ToString());
            string result = "";

            try
            {
                if (ModelState.IsValid && itemMaster != null && itemMaster.PODate.ToString() != "" && itemDetails.Count > 0 && menuID != null)
                {
                    result = objPurchaseOrder.SaveUpdatePOMasterNdetails(itemMaster, itemDetails, menuID, fileNames, termslist);
                    PONo   = result;
                }
                else
                {
                    result = "";
                }
            }
            catch (Exception e)
            {
                e.ToString();
                result = "";
            }

            return(Request.CreateResponse(HttpStatusCode.OK, result));
        }
        public string SaveUpdatePOMasterNdetails(PurchasePOMaster chMaster, List <PurchasePODetail> chDetails, int menuID, ArrayList fileNames, List <vmTermsCondition> termdetail)
        {
            _ctxCmn = new ERP_Entities();
            GenericFactory_EF_CmnCombo = new CmnCombo_EF();
            string result = "";

            if (chMaster.POID > 0)
            {
                using (TransactionScope transaction = new TransactionScope())
                {
                    try
                    {
                        Int64 poID = chMaster.POID;
                        IEnumerable <PurchasePOMaster> lstPurchasePOMaster = (from qcm in _ctxCmn.PurchasePOMasters.Where(m => m.POID == poID && m.CompanyID == chMaster.CompanyID) select qcm).ToList();
                        PurchasePOMaster objPurchasePOMaster = new PurchasePOMaster();
                        foreach (PurchasePOMaster qcms in lstPurchasePOMaster)
                        {
                            qcms.UpdateBy          = chMaster.CreateBy;
                            qcms.UpdateOn          = DateTime.Now;
                            qcms.UpdatePc          = HostService.GetIP();
                            qcms.POID              = chMaster.POID;
                            qcms.CurrencyID        = chMaster.CurrencyID;
                            qcms.Amount            = chMaster.Amount;
                            qcms.PODate            = chMaster.PODate;
                            qcms.BankAccountNo     = chMaster.BankAccountNo;
                            qcms.DepartmentID      = chMaster.DepartmentID;
                            qcms.TransactionTypeID = chMaster.TransactionTypeID;
                            qcms.BankBranchID      = chMaster.BankBranchID;
                            qcms.IsDeleted         = false;
                            qcms.BankID            = chMaster.BankID;
                            qcms.PartyID           = chMaster.PartyID;
                            //qcms.PIID = chMaster.PIID;
                            qcms.CompanyID  = chMaster.CompanyID;
                            qcms.ExpireDate = chMaster.ExpireDate;
                            //qcms.FRID= chMaster.FRID;
                            qcms.LCorVoucherorLcafDate  = chMaster.LCorVoucherorLcafDate;
                            qcms.LCorVoucherorLcafNo    = chMaster.LCorVoucherorLcafNo;
                            qcms.MoneyTransactionTypeID = chMaster.MoneyTransactionTypeID;
                            qcms.OrderTypeID            = chMaster.OrderTypeID;
                            qcms.RequisitionID          = qcms.RequisitionID;
                            qcms.ShipmentDate           = qcms.ShipmentDate;
                            objPurchasePOMaster         = qcms;
                        }
                        List <PurchasePODetail> lstPurchasePODetail = new List <PurchasePODetail>();
                        foreach (PurchasePODetail qcdt in chDetails)
                        {
                            PurchasePODetail objPurchasePODetail = (from qcdetl in _ctxCmn.PurchasePODetails.Where(m => m.PODetailID == qcdt.PODetailID) select qcdetl).FirstOrDefault();

                            objPurchasePODetail.Amount          = qcdt.Amount;
                            objPurchasePODetail.FOBValue        = qcdt.FOBValue;
                            objPurchasePODetail.FreightCharge   = qcdt.FreightCharge;
                            objPurchasePODetail.HSCode          = qcdt.HSCode;
                            objPurchasePODetail.ItemID          = qcdt.ItemID;
                            objPurchasePODetail.NetWeight       = qcdt.NetWeight;
                            objPurchasePODetail.IsDeleted       = false;
                            objPurchasePODetail.GrossWeight     = qcdt.GrossWeight;
                            objPurchasePODetail.OriginCountryID = qcdt.OriginCountryID;
                            objPurchasePODetail.NetWeight       = qcdt.NetWeight;
                            objPurchasePODetail.PackingQty      = qcdt.PackingQty;
                            objPurchasePODetail.PackingUnitID   = qcdt.PackingUnitID;
                            objPurchasePODetail.Qty             = qcdt.Qty;
                            objPurchasePODetail.UnitID          = qcdt.UnitID;
                            objPurchasePODetail.UnitPrice       = qcdt.UnitPrice;
                            objPurchasePODetail.WeightUnitID    = qcdt.WeightUnitID;
                            objPurchasePODetail.UpdateBy        = chMaster.CreateBy;
                            objPurchasePODetail.UpdateOn        = DateTime.Now;
                            objPurchasePODetail.UpdatePc        = HostService.GetIP();
                            lstPurchasePODetail.Add(objPurchasePODetail);
                        }
                        _ctxCmn.SaveChanges();

                        //**********----------------------Start File Upload----------------------**********
                        GenericFactory_CmnDocument = new CmnDocument_EF();
                        int DocumentID = Convert.ToInt16(GenericFactory_CmnDocument.getMaxID("CmnDocument"));
                        List <CmnDocument> lstCmnDocument = new List <CmnDocument>();

                        for (int i = 1; i <= fileNames.Count; i++)
                        {
                            CmnDocument objCmnDocument = new CmnDocument();
                            objCmnDocument.DocumentID     = DocumentID;
                            objCmnDocument.DocumentPahtID = 2;
                            //objCmnDocument.DocumentName = fileNames[i].ToString();
                            string extension = System.IO.Path.GetExtension(fileNames[i - 1].ToString());
                            objCmnDocument.DocumentName      = chMaster.PONo + "_Doc_" + i + extension;
                            objCmnDocument.TransactionID     = chMaster.POID;
                            objCmnDocument.TransactionTypeID = 22;
                            objCmnDocument.CompanyID         = chMaster.CompanyID;
                            objCmnDocument.CreateBy          = Convert.ToInt16(chMaster.CreateBy);
                            objCmnDocument.CreateOn          = DateTime.Now;
                            objCmnDocument.CreatePc          = HostService.GetIP();
                            objCmnDocument.IsDeleted         = false;

                            objCmnDocument.IsDeleted = false;
                            lstCmnDocument.Add(objCmnDocument);

                            DocumentID++;
                        }

                        GenericFactory_CmnDocument.InsertList(lstCmnDocument);
                        GenericFactory_CmnDocument.Save();
                        GenericFactory_CmnDocument.updateMaxID("CmnDocument", Convert.ToInt64(DocumentID - 1));

                        //**********----------------------File upload completed----------------------**********

                        transaction.Complete();
                        result = chMaster.PONo.ToString();
                    }
                    catch (Exception e)
                    {
                        e.ToString();
                        result = "";
                    }
                }
            }
            else
            {
                using (TransactionScope transaction = new TransactionScope())
                {
                    try
                    {
                        //...........START  new maxId...............//
                        long NextId = Convert.ToInt16(GenericFactory_EF_CmnCombo.getMaxID("PurchasePOMaster"));

                        long FirstDigit     = 0;
                        long OtherDigits    = 0;
                        long nextChDetailId = Convert.ToInt16(GenericFactory_EF_CmnCombo.getMaxID("PurchasePODetail"));
                        FirstDigit  = Convert.ToInt64(nextChDetailId.ToString().Substring(0, 1));
                        OtherDigits = Convert.ToInt64(nextChDetailId.ToString().Substring(1, nextChDetailId.ToString().Length - 1));
                        //..........END new maxId....................//


                        //......... START for custom code........... //

                        string customCode = "";
                        string CustomNo   = GenericFactory_EF_CmnCombo.getCustomCode(menuID, chMaster.PODate ?? DateTime.Now, chMaster.CompanyID ?? 1, 1, 1);

                        if (CustomNo != null)
                        {
                            customCode = CustomNo;
                        }
                        else
                        {
                            customCode = NextId.ToString();
                        }

                        //.........END for custom code............ //

                        string newChNo = customCode;
                        chMaster.POID      = NextId;
                        chMaster.CreateOn  = DateTime.Now;
                        chMaster.CreatePc  = HostService.GetIP();
                        chMaster.PONo      = newChNo;
                        chMaster.IsDeleted = false;


                        List <PurchasePODetail> lstchDetail = new List <PurchasePODetail>();
                        foreach (PurchasePODetail sdtl in chDetails)
                        {
                            PurchasePODetail objchDetail = new PurchasePODetail();
                            objchDetail.PODetailID      = Convert.ToInt64(FirstDigit + "" + OtherDigits);//nextQCDetailId;
                            objchDetail.POID            = NextId;
                            objchDetail.FOBValue        = sdtl.FOBValue;
                            objchDetail.FreightCharge   = sdtl.FreightCharge;
                            objchDetail.HSCode          = sdtl.HSCode;
                            objchDetail.OriginCountryID = sdtl.OriginCountryID;
                            objchDetail.ItemID          = sdtl.ItemID;
                            objchDetail.GrossWeight     = sdtl.GrossWeight;
                            objchDetail.NetWeight       = sdtl.NetWeight;
                            objchDetail.PackingQty      = sdtl.PackingQty;
                            objchDetail.PackingUnitID   = sdtl.PackingUnitID;
                            objchDetail.UnitID          = sdtl.UnitID;
                            objchDetail.UnitPrice       = sdtl.UnitPrice;
                            objchDetail.WeightUnitID    = sdtl.WeightUnitID;
                            objchDetail.Qty             = sdtl.Qty;
                            objchDetail.IsDeleted       = false;
                            objchDetail.Amount          = sdtl.Amount;
                            objchDetail.UnitID          = sdtl.UnitID;
                            objchDetail.CreateBy        = chMaster.CreateBy;
                            objchDetail.CreateOn        = DateTime.Now;
                            objchDetail.CreatePc        = HostService.GetIP();
                            lstchDetail.Add(objchDetail);
                            OtherDigits++;

                            // InvGrrDetail objInvGrrDetail = (from grrd in _ctxCmn.InvGrrDetails.Where(m => m.GrrID == qcMaster.GrrID && m.ItemID == sdtl.ItemID) select grrd).FirstOrDefault();
                            // objInvGrrDetail.QcRemainingQty = objInvGrrDetail.QcRemainingQty - (sdtl.PassQty + sdtl.RejectQty);
                        }

                        _ctxCmn.PurchasePOMasters.Add(chMaster);

                        //............Save Term and condition.................//
                        if (termdetail.Count > 0)
                        {
                            long FirstDigits  = 0;
                            long OtherDigitss = 0;
                            long NextPOTermID = Convert.ToInt16(GenericFactory_EF_CmnCombo.getMaxID("PurchasePOTerm"));
                            FirstDigits  = Convert.ToInt64(NextPOTermID.ToString().Substring(0, 1));
                            OtherDigitss = Convert.ToInt64(NextPOTermID.ToString().Substring(1, NextPOTermID.ToString().Length - 1));

                            List <PurchasePOTerm> lstTerms = new List <PurchasePOTerm>();
                            foreach (vmTermsCondition sdtl in termdetail)
                            {
                                PurchasePOTerm objchDetail = new PurchasePOTerm();
                                objchDetail.POTermsID = Convert.ToInt64(FirstDigits + "" + OtherDigitss);//nextQCDetailId;
                                objchDetail.POID      = NextId;
                                objchDetail.TermID    = Convert.ToInt32(sdtl.TermID);
                                objchDetail.CompanyID = Convert.ToInt16(chMaster.CompanyID);
                                objchDetail.Sequence  = sdtl.Sequence;
                                objchDetail.IsDeleted = false;
                                objchDetail.CreateBy  = Convert.ToInt32(chMaster.CreateBy);
                                objchDetail.CreateOn  = DateTime.Now;
                                objchDetail.CreatePc  = HostService.GetIP();
                                lstTerms.Add(objchDetail);
                                OtherDigitss++;
                            }
                            _ctxCmn.PurchasePOTerms.AddRange(lstTerms);

                            //............Update MaxID.................//
                            GenericFactory_EF_CmnCombo.updateMaxID("PurchasePOTerm", Convert.ToInt64(FirstDigits + "" + (OtherDigitss - 1)));
                        }

                        //............Update MaxID.................//
                        GenericFactory_EF_CmnCombo.updateMaxID("PurchasePOMaster", Convert.ToInt64(NextId));
                        //............Update CustomCode.............//
                        GenericFactory_EF_CmnCombo.updateCustomCode(menuID, chMaster.PODate ?? DateTime.Now, chMaster.CompanyID ?? 1, 1, 1);
                        _ctxCmn.PurchasePODetails.AddRange(lstchDetail);

                        //............Update MaxID.................//
                        GenericFactory_EF_CmnCombo.updateMaxID("PurchasePODetail", Convert.ToInt64(FirstDigit + "" + (OtherDigits - 1)));
                        _ctxCmn.SaveChanges();

                        //**********----------------------Start File Upload----------------------**********
                        GenericFactory_CmnDocument = new CmnDocument_EF();
                        int DocumentID = Convert.ToInt16(GenericFactory_CmnDocument.getMaxID("CmnDocument"));
                        List <CmnDocument> lstCmnDocument = new List <CmnDocument>();

                        for (int i = 1; i <= fileNames.Count; i++)
                        {
                            CmnDocument objCmnDocument = new CmnDocument();
                            objCmnDocument.DocumentID     = DocumentID;
                            objCmnDocument.DocumentPahtID = 2;
                            //objCmnDocument.DocumentName = fileNames[i].ToString();
                            string extension = System.IO.Path.GetExtension(fileNames[i - 1].ToString());
                            objCmnDocument.DocumentName      = chMaster.PONo + "_Doc_" + i + extension;
                            objCmnDocument.TransactionID     = chMaster.POID;
                            objCmnDocument.TransactionTypeID = 22;
                            objCmnDocument.CompanyID         = chMaster.CompanyID;
                            objCmnDocument.CreateBy          = Convert.ToInt16(chMaster.CreateBy);
                            objCmnDocument.CreateOn          = DateTime.Now;
                            objCmnDocument.CreatePc          = HostService.GetIP();
                            objCmnDocument.IsDeleted         = false;

                            objCmnDocument.IsDeleted = false;
                            lstCmnDocument.Add(objCmnDocument);

                            DocumentID++;
                        }

                        GenericFactory_CmnDocument.InsertList(lstCmnDocument);
                        GenericFactory_CmnDocument.Save();
                        GenericFactory_CmnDocument.updateMaxID("CmnDocument", Convert.ToInt64(DocumentID - 1));

                        //**********----------------------File upload completed----------------------**********

                        transaction.Complete();
                        result = newChNo;
                    }
                    catch (Exception e)
                    {
                        result = "";
                    }
                }
            }
            return(result);
        }