/// <summary>
 /// Save and Update Booking Details
 /// </summary>
 /// <param name="bookingDetails"></param>
 /// <returns></returns>
 public int SaveAndUpdateBookingDetail(BookingDTO bookingDetails)
 {
     booking bookingEntity = new booking();
     AutoMapper.Mapper.Map(bookingDetails, bookingEntity);
     if (bookingDetails.Booking_Id == 0)
     {
         ESalesUnityContainer.Container.Resolve<IGenericRepository<booking>>().Save(bookingEntity);
     }
     else
     {
         ESalesUnityContainer.Container.Resolve<IGenericRepository<booking>>().Update(bookingEntity);
     }
     return bookingEntity.Booking_Id;
 }
        /// <summary>
        /// Get Booking Detail By BookingId
        /// </summary>
        /// <param name="bookingId">Int32:bookingId</param>
        /// <param name="isMoneyReceiptIssued">bool:isMoneyReceiptIssued</param>
        /// <returns></returns>
        public BookingDTO GetBookingDetailByBookingId(int bookingId, bool isMoneyReceiptIssued)
        {
            BookingDTO bookingDetails = new BookingDTO();

            if (isMoneyReceiptIssued == true)
            {
                AutoMapper.Mapper.Map(ESalesUnityContainer.Container.Resolve<IGenericRepository<booking>>()
                    .GetSingle(item => item.Booking_Id == bookingId && item.Booking_MoneyReceiptIssued == true
                        && item.Booking_AccountSettled == false && item.Booking_IsDeleted == false), bookingDetails);
            }
            else
            {
                AutoMapper.Mapper.Map(ESalesUnityContainer.Container.Resolve<IGenericRepository<booking>>()
                    .GetSingle(item => item.Booking_Id == bookingId && item.Booking_IsDeleted == false
                    && item.Booking_MoneyReceiptIssued == false), bookingDetails);
            }
            return bookingDetails;
        }
    /// <summary>
    /// Initialize booking details for save in database
    /// </summary>
    /// <param name="agentId">Int32: agentId</param>
    /// <returns>returns booking details</returns>
    private BookingDTO InitializeBookingDetails(int agentId)
    {
        BookingDTO bookingDetails = new BookingDTO();

        bookingDetails.Booking_Cust_Id = Convert.ToInt32(ViewState[Globals.StateMgmtVariables.CUSTOMERID]);
        if (Session[Globals.StateMgmtVariables.BOOKINGID] != null)
        {
            bookingDetails.Booking_Id = Convert.ToInt32(Session[Globals.StateMgmtVariables.BOOKINGID]);
        }
        if (agentId != 0)
        {
            bookingDetails.Booking_Agent_Id = agentId;
        }
        if (rdStandAlone.SelectedItem.Value == "1")
        {
            bookingDetails.Booking_Truck_Id = Convert.ToInt32(ddlTruck.SelectedItem.Value);
        }
        else
        {
            bookingDetails.Booking_TruckType = true;
            bookingDetails.Booking_StandAlone_Truck_Id = Convert.ToInt32(ViewState[Globals.StateMgmtVariables.TRUCKID]);
        }

        bookingDetails.Booking_MaterialType_Id = Convert.ToInt32(ddlMaterial.SelectedItem.Value);
        bookingDetails.Booking_AdvanceAmount = Convert.ToDecimal(txtAdvanceAmount.Text.Trim());

        bookingDetails.Booking_TotalAdvanceAmount = Convert.ToDecimal(txtTotalBookingAdvance.Text.Trim());
        bookingDetails.Booking_BalanceAmount = Convert.ToDecimal(txtBalanceAdvance.Text.Trim());

        bookingDetails.Booking_TotalIssuedQty = Convert.ToInt32(txtTotalIssuedQty.Text.Trim());
        bookingDetails.Booking_Qty = Convert.ToInt32(txtCurrentQty.Text.Trim());
        bookingDetails.Booking_Status = rdBookingStatus.SelectedItem.Value == "1" ? true : false;
        bookingDetails.Booking_RejectionReson = txtRejectionReason.Text.Trim();
        bookingDetails.Booking_CreatedBy = GetCurrentUserId();
        bookingDetails.Booking_LastUpdatedDate = DateTime.Now;
        bookingDetails.Booking_CreatedDate = DateTime.Now;
        bookingDetails.Booking_Mode = Convert.ToInt32(ViewState[Globals.StateMgmtVariables.BOOKINGMODEID]);
        bookingDetails.Booking_Date = Convert.ToDateTime(txtBookingDate.Text);
        return bookingDetails;
    }
        public void SaveAllRejectedBookingInfo(BookingDTO bookingDetails, int smsRegId)
        {
            using (TransactionScope transactionScope = new TransactionScope())
            {

                //Save Booking Details
                int savedBookingID = SaveAndUpdateBookingDetail(bookingDetails);
                if (smsRegId > 0)
                {
                    SMSRegistrationDTO smsRegdetails = ESalesUnityContainer.Container.Resolve<ISMSService>().GetTodaysSMSDetailsById(smsRegId, DateTime.Now.Date.AddDays(-1));
                    smsRegdetails.SMSReg_Booking_Id = savedBookingID;
                    ESalesUnityContainer.Container.Resolve<ISMSService>().SaveAndUpdateSMSDetails(smsRegdetails);
                }
                transactionScope.Complete();
            }
        }
        /// <summary>
        /// Get Booking Detail By SmsId
        /// </summary>
        /// <param name="smsId">Int32:smsId</param>
        /// <returns></returns>
        public BookingDTO GetBookingDetailBySmsId(int smsId)
        {
            SMSRegistrationDTO smsDetails = new SMSRegistrationDTO();
            BookingDTO bookingDetails = new BookingDTO();

            AutoMapper.Mapper.Map(ESalesUnityContainer.Container.Resolve<IGenericRepository<smsregistration>>()
                .GetSingle(item => item.SMSReg_Id == smsId && item.SMSReg_BookingStatus == true && item.SMSReg_IsDeleted == false), smsDetails);

            if (smsDetails.SMSReg_Id > 0)
            {
                AutoMapper.Mapper.Map(ESalesUnityContainer.Container.Resolve<IGenericRepository<booking>>()
                    .GetSingle(item => item.Booking_Id == smsDetails.SMSReg_Booking_Id && item.Booking_MoneyReceiptIssued == true
                        && item.Booking_AccountSettled == false && item.Booking_IsDeleted == false), bookingDetails);
            }
            return bookingDetails;
        }
 /// <summary>
 /// Get Booking Detail By BookingId
 /// </summary>
 /// <param name="bookingId">Int32:bookingId</param>
 /// <returns></returns>
 public BookingDTO GetBookingDetailForReprint(int bookingId)
 {
     BookingDTO bookingDetails = new BookingDTO();
     AutoMapper.Mapper.Map(ESalesUnityContainer.Container.Resolve<IGenericRepository<booking>>()
         .GetSingle(item => item.Booking_Id == bookingId && item.Booking_IsDeleted == false), bookingDetails);
     return bookingDetails;
 }
 /// <summary>
 /// Get Truck Count For date for the barcode application
 /// </summary>
 /// <param name="currentDate">DateTime:currentDate</param>
 /// <param name="TruckInformation">Int32:truckstatus</param>
 /// <returns></returns>
 public int GetTruckCountForDateBarcode(DateTime currentDate, int truckStatus)
 {
     BookingDTO bookingDetails = new BookingDTO();
     int count = 0;
     if (truckStatus == 1)
     {
         List<booking> lstBookingEntity = ESalesUnityContainer.Container.Resolve<IGenericRepository<booking>>().GetQuery().
        Where(item => item.Booking_TruckInTime >= currentDate && item.Booking_Status == true
        && item.Booking_IsDeleted == false)
        .OrderBy(order => order.Booking_CreatedDate).ToList();
         count = lstBookingEntity.Count;
     }
     else if (truckStatus == 2)
     {
         List<booking> lstBookingEntity = ESalesUnityContainer.Container.Resolve<IGenericRepository<booking>>().GetQuery().
        Where(item => item.Booking_TruckMatLiftedTime >= currentDate && item.Booking_Status == true
       && item.Booking_IsDeleted == false)
        .OrderBy(order => order.Booking_CreatedDate).ToList();
         count = lstBookingEntity.Count;
     }
     else
     {
         count = 0;
     }
     return count;
 }
 /// <summary>
 /// Get Truck Count For Date
 /// </summary>
 /// <param name="truckId">Int32:</param>
 /// <param name="currentDate">DateTime:currentDate</param>
 /// <param name="truckType">Int32:truckType</param>
 /// <returns></returns>
 public int GetTruckCountForDate(int truckId, DateTime currentDate, int truckType)
 {
     BookingDTO bookingDetails = new BookingDTO();
     int count = 0;
     if (truckType == 1)
     {
         List<booking> lstBookingEntity = ESalesUnityContainer.Container.Resolve<IGenericRepository<booking>>().GetQuery().
        Where(item => item.Booking_Date == currentDate && item.Booking_Status == true
       && item.Booking_Truck_Id == truckId && item.Booking_IsDeleted == false)
        .OrderBy(order => order.Booking_CreatedDate).ToList();
         count = lstBookingEntity.Count;
     }
     else
     {
         List<booking> lstBookingEntity = ESalesUnityContainer.Container.Resolve<IGenericRepository<booking>>().GetQuery().
        Where(item => item.Booking_Date == currentDate && item.Booking_Status == true
       && item.Booking_StandAlone_Truck_Id == truckId && item.Booking_IsDeleted == false)
        .OrderBy(order => order.Booking_CreatedDate).ToList();
         count = lstBookingEntity.Count;
     }
     return count;
 }
        /// <summary>
        /// To Save all booking Info
        /// </summary>
        /// <param name="lstDCAMaterialAllocation"></param>
        /// <param name="bookingDetails"></param>
        /// <param name="counterDailyDetail"></param>
        /// <param name="smsRegId"></param>
        /// <returns></returns>
        public string SaveAllBookingInfo(IList<DcaMaterialAllocationDTO> lstDCAMaterialAllocation, BookingDTO bookingDetails,
            CounterDetailsDTO counterDailyDetail, int smsRegId)
        {
            using (TransactionScope transactionScope = new TransactionScope())
            {
                DcaMaterialAllocationService dcaMatAllocationService = new DcaMaterialAllocationService();
                //update agent details
                dcaMatAllocationService.SaveAndUpdateDCAMaterialDetails(lstDCAMaterialAllocation);

                bookingDetails.Booking_CounterId = counterDailyDetail.CounterDetail_Counter_ID;
                bookingDetails.Booking_Status = true;

                //Save Booking Details
                int savedBookingID = SaveAndUpdateBookingDetail(bookingDetails);

                //update counter Details
                counterDailyDetail.CounterDetail_Count += 1;
                CounterService counters = new CounterService();
                counters.UpdateCounterDailyDetails(counterDailyDetail);
                //update SMS Details
                if (smsRegId > 0)
                {
                    SMSRegistrationDTO smsRegdetails = ESalesUnityContainer.Container.Resolve<ISMSService>().GetTodaysSMSDetailsById(smsRegId, DateTime.Now.Date.AddDays(-1));
                    smsRegdetails.SMSReg_Booking_Id = savedBookingID;
                    ESalesUnityContainer.Container.Resolve<ISMSService>().SaveAndUpdateSMSDetails(smsRegdetails);
                }
                transactionScope.Complete();
                return counterDailyDetail.CounterDetail_Counter_ID.ToString();
            }
        }
	/// <summary>
	/// Set Report Parameters by bookingDetails and reportViewer
	/// </summary>
	/// <param name="bookingDetails"></param>
	/// <param name="reportViewer"></param>
    private void SetReportParameters(BookingDTO bookingDetails, ReportViewer reportViewer)
    {
        string truckRegNo = string.Empty;
        string truckOwnerName = string.Empty;
        string truckDriverName = string.Empty;
        string truckOwnerShortAdd = string.Empty;
        string truckDriverShortAdd = string.Empty;
        BarcodeDTO b = new BarcodeDTO();
        SMSRegistrationDTO smsDetail = new SMSRegistrationDTO();
        smsDetail = ESalesUnityContainer.Container.Resolve<ISMSService>().GetSmsDetailsByBookingId(bookingDetails.Booking_Id);

        ReportParameter loadingAdviceFor = new ReportParameter("LoadingAdviceFor", bookingDetails.Booking_MaterialType_MaterialName);
        ReportParameter loadingAdviceNo = new ReportParameter("LoadingAdviceNo", bookingDetails.Booking_Agent_AgentShortName
            + "-" + bookingDetails.Booking_Id);
        ReportParameter sNO = new ReportParameter("SNo", Convert.ToString(bookingDetails.Booking_Id));
        ReportParameter bookingDate = new ReportParameter("BookingDate", Convert.ToDateTime(bookingDetails.Booking_Date).ToString("dd/MMM/yyyy"));
        ReportParameter matTypeName = new ReportParameter("MatTypeName", bookingDetails.Booking_MaterialType_MaterialName);
        ReportParameter matCode = new ReportParameter("MatCode", bookingDetails.Booking_MaterialType_Code);
        ReportParameter custCode = new ReportParameter("CustCode", bookingDetails.Booking_Cust_Code);
        ReportParameter smsId1 = new ReportParameter("SMSId1", Convert.ToString(smsDetail.SMSReg_Id));
        ReportParameter smsId2 = new ReportParameter("SMSId2", Convert.ToString(smsDetail.SMSReg_Id));

        if (bookingDetails.Booking_TruckType == true)
        {
            truckRegNo = bookingDetails.Booking_StandaloneTruck_RegNo;
            truckOwnerName = bookingDetails.Booking_StandaloneTruck_OwnerName + ',' + bookingDetails.Booking_StandaloneTruck_OwnerShortAdd;
            truckDriverName = bookingDetails.Booking_StandaloneTruck_DriverName + ',' + bookingDetails.Booking_StandaloneTruck_DriverShortAdd;
        }
        else
        {
            truckRegNo = bookingDetails.Booking_Truck_RegNo;
            truckOwnerName = bookingDetails.Booking_Truck_OwnerName + ',' + bookingDetails.Booking_Truck_OwnerShortAdd;
            truckDriverName = bookingDetails.Booking_Truck_DriverName + ',' + bookingDetails.Booking_Truck_DriverShortAdd;
        }

        ReportParameter truckNo = new ReportParameter("TruckNo", truckRegNo);
        ReportParameter truckOwner = new ReportParameter("TruckOwner", truckOwnerName);
        ReportParameter truckDriver = new ReportParameter("TruckDriver", truckDriverName);
        ReportParameter custName = new ReportParameter("CustName", bookingDetails.Booking_Cust_UnitName);
        ReportParameter address = new ReportParameter("Address", bookingDetails.Booking_Cust_UnitAddress);
        ReportParameter district = new ReportParameter("District", bookingDetails.Booking_Cust_District_Name);
        ReportParameter state = new ReportParameter("State", bookingDetails.Booking_Cust_State_Name);
        ReportParameter approxQty = new ReportParameter("AppQty", Convert.ToString(bookingDetails.Booking_Qty) + " M");

        CurrencyConvertor currencyConvertor = new CurrencyConvertor();

        MoneyReceiptDTO moneyReceiptDetails = MasterList.GetMoneyReceiptById(0, bookingDetails.Booking_Id);

        ReportParameter advanceAmount = new ReportParameter("AdvanceAmount",
            Convert.ToString(moneyReceiptDetails.MoneyReceipt_AmountPaid));
        ReportParameter amountInWords = new ReportParameter("AmountInWords",
            currencyConvertor.Convertor(moneyReceiptDetails.MoneyReceipt_AmountPaid.ToString()));
        ReportParameter moneyReceiptDate = new ReportParameter("MoneyReceiptDate",
            Convert.ToDateTime(moneyReceiptDetails.MoneyReceipt_CreateDate).ToString("dd/MMM/yyyy"));

        ReportParameter moneyReceiptSNo = new ReportParameter("MoneyReceiptSNo", Convert.ToString(moneyReceiptDetails.MoneyReceipt_Id));

        GenerateBarcode(bookingDetails.Booking_Id.ToString(), ref b);

        List<BarcodeDTO> barcodes = new List<BarcodeDTO>();
        barcodes.Add(b);
        reportViewer.LocalReport.DataSources.Clear();
        reportViewer.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", barcodes));

        reportViewer.LocalReport.SetParameters(new ReportParameter[] { loadingAdviceFor, loadingAdviceNo, sNO, 
			bookingDate, matTypeName, matCode, custCode, truckNo, truckOwner, truckDriver, custName, address, district, state,
			approxQty, advanceAmount, amountInWords, moneyReceiptSNo, moneyReceiptDate, smsId1, smsId2});
    }
    /// <summary>
    /// Event for Accept Save by booking Id
    /// </summary>
    /// <param name="bookingId"></param>
    private void AcceptSave(int bookingId)
    {
        string counterId = string.Empty;
        int agentId = 0;
        BookingDTO bookingDetails = new BookingDTO();

        bookingDetails = ESalesUnityContainer.Container.Resolve<IBookingService>().GetBookingDetailByBookingId(bookingId, false);
        CustomerDTO customer = ESalesUnityContainer.Container.Resolve<ICustomerService>()
            .GetCustomerDetailsById(bookingDetails.Booking_Cust_Id);
		int smsRegId = 0;
        
        ViewState[Globals.StateMgmtVariables.AGENTID] = customer.Cust_AgentId;
        
        IList<DcaMaterialAllocationDTO> lstMaterialAllocations = ESalesUnityContainer.Container
            .Resolve<IDcaMaterialAllocationService>()
            .GetMaterialAllocationDetails(bookingDetails.Booking_MaterialType_Id, DateTime.Now.Date);

        if (lstMaterialAllocations.Count > 0)
        {
            if (ViewState[Globals.StateMgmtVariables.AGENTID] == null)
            {
                agentId = (from F in lstMaterialAllocations where F.DCAMA_AllocatedQty == 0 
                           select F.DCAMA_Agent_Id).FirstOrDefault();

                if (agentId == 0)
                {
                    agentId = (from F in lstMaterialAllocations orderby F.DCAMA_CurrentVariance descending 
                               select F.DCAMA_Agent_Id).FirstOrDefault();
                }
            }
            else
            {
                agentId = (from F in lstMaterialAllocations 
                           where F.DCAMA_Agent_Id == Convert.ToInt32(ViewState[Globals.StateMgmtVariables.AGENTID])
                           select F.DCAMA_Agent_Id).FirstOrDefault();
            }

            if (agentId != 0)
            {
                int qtySum = (from F in lstMaterialAllocations
                              select F.DCAMA_AllocatedQty).Sum() + Convert.ToInt32(bookingDetails.Booking_Qty);

                foreach (DcaMaterialAllocationDTO item in lstMaterialAllocations)
                {
                    if (item.DCAMA_Agent_Id == agentId)
                    {
                        item.DCAMA_AllocatedQty += Convert.ToInt32(bookingDetails.Booking_Qty);
                        item.DCAMA_LastQty = Convert.ToInt32(bookingDetails.Booking_Qty);
                    }
                    item.DCAMA_CurrentPercentage = (Convert.ToDecimal(item.DCAMA_AllocatedQty) / Convert.ToDecimal(qtySum)) * 100;
                    item.DCAMA_CurrentVariance = item.DCAMA_TodayPercentage - item.DCAMA_CurrentPercentage;
                }

                bookingDetails.Booking_Agent_Id = agentId;
                bookingDetails.Booking_IsAdvanced = false;
                counterId = ESalesUnityContainer.Container.Resolve<IBookingService>()
					.SaveAllBookingInfo(lstMaterialAllocations, bookingDetails, GetCounterID(agentId), smsRegId);

                CounterDTO counterDetails = ESalesUnityContainer.Container.Resolve<ICounterService>().GetCounterDetailsById(Convert.ToInt32(counterId));

                lblCounterNo.Visible = true;
                lblCounterNo.Text = Messages.GoToCounterNo + counterDetails.Counter_Name;
            }
            else
            {
                ucMessageBox.ShowMessage(Messages.AgentNotActive);
            }
        }
        else
        {
            ucMessageBox.ShowMessage(Messages.AgentNotActive);
        }
    }
Esempio n. 12
0
 public static BookingDTO GetBookingDetailByBookingId(int bookingId, bool isMoneyReceiptIssued)
 {
     BookingDTO bookingDetail = new BookingDTO();
     bookingDetail = ESalesUnityContainer.Container.Resolve<IBookingService>().GetBookingDetailByBookingId(bookingId, 
         isMoneyReceiptIssued);
     return bookingDetail;
 }