Пример #1
0
        void grdPaymentHistory_CommandCellClick(object sender, EventArgs e)
        {
            try
            {
                GridCommandCellElement gridCell = (GridCommandCellElement)sender;
                if (gridCell.ColumnInfo.Name.ToLower() == "btndelete")
                {
                    if (DialogResult.Yes == RadMessageBox.Show("Are you sure you want to delete a Record ? ", "", MessageBoxButtons.YesNo, RadMessageIcon.Question))
                    {
                        long Id = grdPaymentHistory.CurrentRow.Cells["Id"].Value.ToLong();
                        if (grdPaymentHistory.CurrentRow != null && grdPaymentHistory.CurrentRow is GridViewDataRowInfo)
                        {
                            if (grdPaymentHistory.Rows.Count > 1 && Id < grdPaymentHistory.Rows.Where(c => c.Index != grdPaymentHistory.CurrentRow.Index)
                                .OrderByDescending((c => c.Cells["Id"].Value.ToLong())).FirstOrDefault().Cells["Id"].Value.ToLong())
                            {
                                ENUtils.ShowMessage("Expenses History will be Delete in Reverse Order");
                                return;
                            }
                        }

                        string  Type           = grdPaymentHistory.CurrentRow.Cells[COLS.Type].Value.ToStr().ToLower();
                        decimal Amount         = grdPaymentHistory.CurrentRow.Cells[COLS.Amount].Value.ToDecimal();
                        decimal CurrentBalance = numCurrBalance.Value.ToDecimal();
                        grdPaymentHistory.CurrentRow.Delete();
                        if (Type == "credit")
                        {
                            //if (CurrentBalance > 0)
                            //{
                            numCurrBalance.Value = (CurrentBalance + Amount);
                        }
                        else
                        {
                            //if (CurrentBalance > 0)
                            //{
                            numCurrBalance.Value = (CurrentBalance - Amount);
                        }
                        objDriverCommision.GetByPrimaryKey(CommissionId);
                        objDriverCommision.Edit();
                        objDriverCommision.Current.Balance = numCurrBalance.Value.ToDecimal();

                        objDriverCommision.Save();
                        using (TaxiDataContext db = new TaxiDataContext())
                        {
                            var query = db.Fleet_DriverCommissionExpenses.Single(c => c.Id == Id);
                            db.Fleet_DriverCommissionExpenses.DeleteOnSubmit(query);
                            db.SubmitChanges();
                        }
                        DisplayRecord();
                    }
                }
            }
            catch (Exception ex)
            {
                ENUtils.ShowMessage(ex.Message);
            }
        }
        private bool OnSave(int DriverId, decimal oldBalance, decimal DriverCommissionPerBooking, decimal pdaCommission, decimal InitialBalance, decimal CommissionPayValue, ref decimal accJobs, ref long transId, ref decimal rentDue, ref decimal currBalance)
        {
            bool IsSaved = false;


            try
            {
                bool RentForProcessedJobs = AppVars.objPolicyConfiguration.RentForProcessedJobs.ToBool();


                var CommissionList = General.GetGeneralList <Fleet_DriverCommision_Charge>(c => c.BookingId != null && c.TransId != null);



                Expression <Func <Booking, bool> > _exp = null;
                if (AppVars.objPolicyConfiguration.PickBookingOnInvoicingType.ToInt() == 2)
                {
                    _exp = c => ((c.PaymentTypeId != Enums.PAYMENT_TYPES.CASH && c.BookingStatusId == Enums.BOOKINGSTATUS.NOPICKUP) || c.BookingStatusId == Enums.BOOKINGSTATUS.DISPATCHED)

                           && (c.FareRate != null) &&
                           ((RentForProcessedJobs == true && (c.IsProcessed != null && c.IsProcessed == true)) || (RentForProcessedJobs == false && (c.IsProcessed == null || c.IsProcessed == false))) &&
                           (c.DriverId == DriverId) &&
                           (c.PickupDateTime.Value.Date >= dtpFromDate.Value.Value.Date && c.PickupDateTime.Value.Date <= dtpTillDate.Value.Value.Date);
                }
                else
                {
                    _exp = c => c.BookingStatusId == Enums.BOOKINGSTATUS.DISPATCHED

                           && (c.FareRate != null) &&
                           ((RentForProcessedJobs == true && (c.IsProcessed != null && c.IsProcessed == true)) || (RentForProcessedJobs == false && (c.IsProcessed == null || c.IsProcessed == false))) &&
                           (c.DriverId == DriverId) &&
                           (c.PickupDateTime.Value.Date >= dtpFromDate.Value.Value.Date && c.PickupDateTime.Value.Date <= dtpTillDate.Value.Value.Date);
                }



                var list2 = (from a in General.GetGeneralList <Booking>(_exp)
                             join b in CommissionList on a.Id equals b.BookingId into table2
                             from b in table2.DefaultIfEmpty()
                             where (b == null)
                             select new
                {
                    Id = a.Id,
                    TotalFare = a.FareRate.ToDecimal(),
                    CompanyId = a.CompanyId,
                    AccountTypeId = a.Gen_Company != null ? a.Gen_Company.AccountTypeId : a.PaymentTypeId,
                    DriverCommissionAmount = a.DriverCommission,
                    DriverCommissionType = a.DriverCommissionType,
                    IsCommissionWise = a.IsCommissionWise,
                    AgentCommission = a.AgentCommission
                }).ToList();


                if (list2.Count > 0)
                {
                    objMaster = new DriverCommisionBO();
                    objMaster.New();

                    List <Fleet_DriverCommision_Charge> ListDetail = (from a in list2
                                                                      select new Fleet_DriverCommision_Charge
                    {
                        //Id = a.Id,
                        TransId = objMaster.Current.Id,
                        BookingId = a.Id,
                        CommissionPerBooking = (a.TotalFare * DriverCommissionPerBooking) / 100
                                               //CommissionPerBooking=a.DriverCommissionAmount
                    }).ToList();


                    decimal Total        = list2.Sum(c => c.TotalFare).ToDecimal();
                    decimal ACCJobsTotal = list2.Where(c => c.CompanyId != null).Sum(c => c.TotalFare).ToDecimal();

                    double totalWeeks = (dtpTillDate.Value.ToDate().Subtract(dtpFromDate.Value.ToDate()).TotalDays) / 7;

                    if (totalWeeks <= 0)
                    {
                        totalWeeks = 1;
                    }

                    decimal TotalPDARent = (pdaCommission * totalWeeks.ToInt());

                    decimal AgentCommission       = list2.Sum(c => c.AgentCommission).ToDecimal();
                    decimal DriverCommissionTotal = 0;
                    DriverCommissionTotal = ((Total - AgentCommission) * DriverCommissionPerBooking / 100);
                    decimal owed = ((AgentCommission + TotalPDARent + DriverCommissionTotal) - ACCJobsTotal);

                    rentDue = owed;


                    objMaster.Current.AccJobsTotal    = ACCJobsTotal;
                    objMaster.Current.DriverOwed      = rentDue;
                    objMaster.Current.CommissionTotal = DriverCommissionTotal;
                    objMaster.Current.JobsTotal       = Total;
                    objMaster.Current.AgentFeesTotal  = AgentCommission;


                    objMaster.Current.CommisionPay = CommissionPayValue.ToDecimal();

                    objMaster.Current.Balance = (rentDue + oldBalance);//RentPay - DriverRent;

                    objMaster.Current.DriverCommision = DriverCommissionPerBooking;

                    // add pda rent
                    objMaster.Current.PDARent = pdaCommission;

                    objMaster.Current.AddBy      = AppVars.LoginObj.LuserId.ToInt();
                    objMaster.Current.AddLog     = AppVars.LoginObj.LoginName.ToStr();
                    objMaster.Current.AddOn      = DateTime.Now;
                    objMaster.Current.TransDate  = DateTime.Now; //dtpTransactionDate.Value.ToDateTime();
                    objMaster.Current.DriverId   = DriverId;     //ddlDriver.SelectedValue.ToIntorNull();
                    objMaster.Current.OldBalance = oldBalance;   // (CurrentBalance - RentPay);
                    objMaster.Current.FromDate   = dtpFromDate.Value.ToDate();
                    objMaster.Current.ToDate     = dtpTillDate.Value.ToDate();
                    objMaster.Current.TransFor   = "Weekly";//ddlDayWise.SelectedText.ToStr();


                    objMaster.Current.Fuel  = 0; //Fuel.ToDecimal();
                    objMaster.Current.Extra = 0; // Extra.ToDecimal();


                    string[] skipProperties = { "Fleet_DriverCommision", "Booking" };
                    IList <Fleet_DriverCommision_Charge> savedList = objMaster.Current.Fleet_DriverCommision_Charges;

                    var list = objMaster.Current.Fleet_DriverCommision_Charges.ToList();


                    Utils.General.SyncChildCollection(ref savedList, ref ListDetail, "Id", skipProperties);


                    objMaster.Save();

                    currBalance = objMaster.Current.Balance.ToDecimal();
                    IsSaved     = true;
                    transId     = objMaster.Current.Id;
                }
            }
            catch (Exception ex)
            {
                if (objMaster.Errors.Count > 0)
                {
                    ENUtils.ShowMessage(objMaster.ShowErrors());
                }
                else
                {
                    ENUtils.ShowMessage(ex.Message);
                }
            }

            return(IsSaved);
        }