Пример #1
0
        public int Save(PRQChemicalPI model, int userId, string pageUrl)
        {
            int CurrentPIID = 0;

            try
            {
                using (TransactionScope transaction = new TransactionScope())
                {
                    using (_context)
                    {
                        #region New_PI_Insert

                        PRQ_ChemicalPI objPI = new PRQ_ChemicalPI();

                        objPI.PINo       = model.PINo;
                        objPI.PIDate     = DalCommon.SetDate(model.PIDate);
                        objPI.PICategory = model.PICategory;
                        objPI.OrderID    = model.OrderID;
                        objPI.OrderNo    = model.OrderNo;

                        objPI.PIReceiveDate = DateTime.Now;

                        if (model.SupplierID == 0)
                        {
                            objPI.SupplierID = null;
                        }
                        else
                        {
                            objPI.SupplierID = model.SupplierID;
                        }

                        if (model.LocalAgent == 0)
                        {
                            objPI.LocalAgent = null;
                        }
                        else
                        {
                            objPI.LocalAgent = model.LocalAgent;
                        }

                        if (model.ForeignAgent == 0)
                        {
                            objPI.ForeignAgent = null;
                        }
                        else
                        {
                            objPI.ForeignAgent = model.ForeignAgent;
                        }

                        if (model.BuyerID == 0)
                        {
                            objPI.PIBeneficiary = null;
                        }
                        else
                        {
                            objPI.PIBeneficiary = model.BuyerID;
                        }

                        if (model.BuyerAddressID == 0)
                        {
                            objPI.BeneficiaryAddressID = null;
                        }
                        else
                        {
                            objPI.BeneficiaryAddressID = model.BuyerAddressID;
                        }

                        if (model.PICurrency == 0)
                        {
                            objPI.PICurrency = null;
                        }
                        else
                        {
                            objPI.PICurrency = model.PICurrency;
                        }

                        if (model.ExchangeCurrency == 0)
                        {
                            objPI.ExchangeCurrency = null;
                        }
                        else
                        {
                            objPI.ExchangeCurrency = model.ExchangeCurrency;
                        }

                        if (model.ExchangeRate == 0)
                        {
                            objPI.ExchangeRate = null;
                        }
                        else
                        {
                            objPI.ExchangeRate = model.ExchangeRate;
                        }

                        if (model.ExchangeValue == 0)
                        {
                            objPI.ExchangeValue = null;
                        }
                        else
                        {
                            objPI.ExchangeValue = model.ExchangeValue;
                        }


                        objPI.PaymentTerm  = model.PaymentTerm;
                        objPI.PaymentMode  = model.PaymentMode;
                        objPI.DeferredDays = model.DeferredDays;


                        if (model.CountryOforigin == 0)
                        {
                            objPI.CountryOforigin = null;
                        }
                        else
                        {
                            objPI.CountryOforigin = model.CountryOforigin;
                        }


                        if (model.BeneficiaryBank == 0)
                        {
                            objPI.BeneficiaryBank = null;
                        }
                        else
                        {
                            objPI.BeneficiaryBank = model.BeneficiaryBank;
                        }

                        //if (model.AdvisingBank == 0)
                        //    objPI.AdvisingBank = null;
                        //else
                        //    objPI.AdvisingBank = model.AdvisingBank;

                        objPI.FreightCharge      = model.FreightCharge;
                        objPI.FreightChargeExtra = model.FreightChargeExtra;

                        objPI.DeliveryTerm = model.DeliveryTerm;
                        objPI.DeliveryMode = model.DeliveryMode;


                        if (model.PortofLoading == 0)
                        {
                            objPI.PortofLoading = null;
                        }
                        else
                        {
                            objPI.PortofLoading = model.PortofLoading;
                        }

                        if (model.PortofDischarge == 0)
                        {
                            objPI.PortofDischarge = null;
                        }
                        else
                        {
                            objPI.PortofDischarge = model.PortofDischarge;
                        }


                        objPI.Transshipment   = model.Transshipment;
                        objPI.PartialShipment = model.PartialShipment;
                        objPI.GoodDelivery    = model.GoodDelivery;
                        objPI.ShippingMark    = model.ShippingMark;

                        if (model.ExpectedShipmentTime == 0)
                        {
                            objPI.ExpectedShipmentTime = null;
                        }
                        else
                        {
                            objPI.ExpectedShipmentTime = model.ExpectedShipmentTime;
                        }


                        objPI.Packing        = model.Packing;
                        objPI.PreShipmentIns = model.PreShipmentIns;

                        if (model.OfferValidityDays == 0)
                        {
                            objPI.OfferValidityDays = null;
                        }
                        else
                        {
                            objPI.OfferValidityDays = model.OfferValidityDays;
                        }


                        objPI.OfferValidityNote = model.OfferValidityNote;
                        objPI.RecordStatus      = "NCF";
                        objPI.SetBy             = userId;
                        objPI.SetOn             = DateTime.Now;

                        objPI.PIStatus = "ODDN";
                        objPI.PIState  = "RNG";
                        //objPI.PIReceiveDate=??
                        //objPI.PINote=??
                        //objPI.RunningStatus= ??
                        //objPI.CostIndicator= ??

                        _context.PRQ_ChemicalPI.Add(objPI);
                        _context.SaveChanges();
                        CurrentPIID = objPI.PIID;
                        #endregion

                        #region Item Insert
                        if (model.PIItemList != null)
                        {
                            foreach (var item in model.PIItemList)
                            {
                                PRQ_ChemicalPIItem objItem = new PRQ_ChemicalPIItem();
                                objItem.PIID         = CurrentPIID;
                                objItem.ItemID       = item.ItemID;
                                objItem.OrderQty     = item.OrderQty;
                                objItem.OrderUnit    = DalCommon.GetUnitCode(item.OrderUnitName);
                                objItem.PackSize     = DalCommon.GetSizeCode(item.PackSizeName);
                                objItem.SizeUnit     = DalCommon.GetUnitCode(item.SizeUnitName);
                                objItem.PackQty      = item.PackQty;
                                objItem.PIQty        = Convert.ToDecimal(item.PackSizeName) * item.PackQty;
                                objItem.PIUnit       = DalCommon.GetUnitCode(item.PIUnitName);
                                objItem.PIUnitPrice  = item.PIUnitPrice;
                                objItem.PITotalPrice = Convert.ToDecimal(item.PackSizeName) * item.PackQty * item.PIUnitPrice;
                                objItem.SupplierID   = item.SupplierID;
                                //objItem.ManufacturerID = item.ManufacturerID;
                                objItem.ItemSource = item.ItemSource;
                                objItem.SetOn      = DateTime.Now;
                                objItem.SetBy      = userId;

                                _context.PRQ_ChemicalPIItem.Add(objItem);
                                _context.SaveChanges();
                            }
                        }
                        #endregion
                    }
                    transaction.Complete();
                }
                return(CurrentPIID);
            }
            catch (Exception e)
            {
                return(CurrentPIID);
            }
        }
 public ValidationMsg Save(PrqChemLocalPurcBill model, int userId, string url)
 {
     try
     {
         using (var tx = new TransactionScope())
         {
             using (_context)
             {
                 var bill = BillConversion(model, userId, url);
                 if (model.BillId == 0)
                 {
                     _context.PRQ_ChemLocalPurcBill.Add(bill);
                     _context.SaveChanges();
                     _mode = 1;
                 }
                 else
                 {
                     _context.SaveChanges();
                     _mode = 2;
                 }
                 if (model.References != null)
                 {
                     foreach (var reference in model.References)
                     {
                         var entityRef = BillReferenceConversion(reference, userId, bill.BillID);
                         if (reference.BillRefId == 0)
                         {
                             _context.PRQ_ChemLocalPurcBillRef.Add(entityRef);
                             _context.SaveChanges();
                         }
                         else
                         {
                             _context.SaveChanges();
                         }
                         if (reference.Items != null)
                         {
                             foreach (var item in reference.Items)
                             {
                                 var entityItem = BillItemConversion(item, userId, bill.BillID, entityRef.BillRefID);
                                 if (item.BillItemId == 0)
                                 {
                                     _context.PRQ_ChemLocalPurcBillItem.Add(entityItem);
                                     _context.SaveChanges();
                                 }
                                 else
                                 {
                                     _context.SaveChanges();
                                 }
                             }
                         }
                     }
                 }
                 tx.Complete();
                 if (_mode == 1)
                 {
                     _validationMsg.ReturnId   = bill.BillID;
                     _validationMsg.ReturnCode = bill.BillNo;
                     _validationMsg.Type       = Enums.MessageType.Success;
                     _validationMsg.Msg        = "Saved successfully.";
                 }
                 if (_mode == 2)
                 {
                     _validationMsg.Type = Enums.MessageType.Update;
                     _validationMsg.Msg  = "Updated successfully.";
                 }
             }
         }
     }
     catch
     {
         _validationMsg.Type = Enums.MessageType.Error;
         _validationMsg.Msg  = "Failed to save.";
     }
     return(_validationMsg);
 }
        public ValidationMsg Save(InvFinishLeatherReceive model, int userid, string pageUrl)
        {
            _vmMsg = new ValidationMsg();
            try
            {
                using (var tx = new TransactionScope())
                {
                    using (_context)
                    {
                        model.FNReceiveNo = DalCommon.GetPreDefineNextCodeByUrl(pageUrl);//DalCommon.GetPreDefineValue("1", "00045");
                        if (model.FNReceiveNo != null)
                        {
                            #region Save Finish Leather Receive Data

                            INV_FinishLeatherReceive tblFinishLeatherReceive = SetToModelObject(model, userid);
                            _context.INV_FinishLeatherReceive.Add(tblFinishLeatherReceive);
                            _context.SaveChanges();
                            #endregion

                            #region Save Finish Leather Receive Item Data
                            if (model.InvFinishLeatherReceiveItemList != null)
                            {
                                foreach (InvFinishLeatherReceiveItem objFinishLeatherReceiveItem in model.InvFinishLeatherReceiveItemList)
                                {
                                    objFinishLeatherReceiveItem.FNReceiveID = tblFinishLeatherReceive.FNReceiveID;
                                    INV_FinishLeatherReceiveItem tblFinishLeatherReceiveItem = SetToIssueItemModelObject(objFinishLeatherReceiveItem, userid);
                                    _context.INV_FinishLeatherReceiveItem.Add(tblFinishLeatherReceiveItem);
                                    _context.SaveChanges();

                                    #region Save Finish Leather Receive Color Data

                                    if (model.InvFinishLeatherReceiveColorList != null)
                                    {
                                        if (objFinishLeatherReceiveItem.FNReceiveItemID != null)
                                        {
                                            foreach (InvFinishLeatherReceiveColor objFinishLeatherReceiveColor in model.InvFinishLeatherReceiveColorList)
                                            {
                                                objFinishLeatherReceiveColor.FNReceiveID     = tblFinishLeatherReceiveItem.FNReceiveID;
                                                objFinishLeatherReceiveColor.FNReceiveItemID = tblFinishLeatherReceiveItem.FNReceiveItemID;


                                                INV_FinishLeatherReceiveColor tblFinishLeatherReceiveColor = SetToReceiveColorModelObject(objFinishLeatherReceiveColor, userid);
                                                _context.INV_FinishLeatherReceiveColor.Add(tblFinishLeatherReceiveColor);
                                                _context.SaveChanges();
                                            }
                                        }
                                    }
                                    #endregion
                                }
                            }
                            #endregion

                            _context.SaveChanges();

                            tx.Complete();
                            //FNReceiveID = tblFinishLeatherReceive.FNReceiveID;
                            //FNReceiveNo = tblFinishLeatherReceive.FNReceiveNo;

                            _vmMsg.Type = Enums.MessageType.Success;
                            _vmMsg.Msg  = "Saved Successfully.";
                        }
                        else
                        {
                            _vmMsg.Type = Enums.MessageType.Error;
                            _vmMsg.Msg  = "Crust Leather No Predefine Value not Found.";
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                if (ex.InnerException.InnerException.Message.Contains("UNIQUE KEY"))
                {
                    _vmMsg.Type = Enums.MessageType.Error;
                    _vmMsg.Msg  = "Crust Leather No Data Already Exit.";
                }
                _vmMsg.Type = Enums.MessageType.Error;
                _vmMsg.Msg  = "Failed to save.";
            }
            return(_vmMsg);
        }
        public int SaveAdjustItemRequest(InvLeatherStockAdjustModel model, int userID)
        {
            var leatherTypeID   = DalCommon.GetLeatherTypeCode("Raw Hide");
            var leatherStatusID = DalCommon.GetLeatherStatusCode("Raw Hide");

            using (TransactionScope transaction = new TransactionScope())
            {
                #region Insert

                Inv_LeatherStockAdjustRequest objAdjustmentRequest = new Inv_LeatherStockAdjustRequest();

                objAdjustmentRequest.PurchaseYear = model.PurchaseYear;
                objAdjustmentRequest.RequestDate  = DalCommon.SetDate(model.RequestDate);
                objAdjustmentRequest.LeatherType  = model.LeatherType;
                objAdjustmentRequest.StoreID      = model.StoreID;
                objAdjustmentRequest.RecordStatus = "NCF";
                objAdjustmentRequest.SetBy        = userID;
                objAdjustmentRequest.SetOn        = DateTime.Now;

                _context.Inv_LeatherStockAdjustRequest.Add(objAdjustmentRequest);
                _context.SaveChanges();

                var currentRequestID = objAdjustmentRequest.RequestID;

                foreach (var item in model.StockAdjustItemList)
                {
                    Inv_LeatherStockAdjustItem objAdjustmentItems = new Inv_LeatherStockAdjustItem();

                    objAdjustmentItems.RequestID       = currentRequestID;
                    objAdjustmentItems.SupplierID      = item.SupplierID;
                    objAdjustmentItems.PurchaseID      = item.ChallanID;
                    objAdjustmentItems.ItemTypeID      = item.ItemTypeID;
                    objAdjustmentItems.LeatherType     = model.LeatherType;
                    objAdjustmentItems.LeatherStatus   = leatherStatusID;
                    objAdjustmentItems.ItemQty         = item.ItemQty;
                    objAdjustmentItems.Unit            = item.Unit;
                    objAdjustmentItems.Remarks         = item.Remarks;
                    objAdjustmentItems.AdjustmentCause = item.AdjustmentCause;



                    _context.Inv_LeatherStockAdjustItem.Add(objAdjustmentItems);
                    _context.SaveChanges();
                }

                transaction.Complete();
                return(currentRequestID);

                #endregion
            }
        }