Ejemplo n.º 1
0
        //bill calculate with 7 Layer detail with Box Type(Flat or Block Type)
        private decimal getMeterFeesAmountwith7LayerCode(MBMS.DAL.MeterUnitCollect meterUnitCollect)
        {
            decimal        result         = 0;
            decimal        sumUnits       = 0;
            BillCode7Layer billCode7Layer = meterbillcalculateservice.GetBillCode7LayerByBillCode(Convert.ToInt64(meterUnitCollect.Customer.BillCode7Layer.BillCode7LayerNo));
            List <BillCode7LayerDetail> billCode7LayerDetailList = meterbillcalculateservice.GetBillCode7LayerDetailByBillCode7LayerID(billCode7Layer.BillCode7LayerID).OrderBy(y => y.LowerLimit).ToList();

            foreach (BillCode7LayerDetail item in billCode7LayerDetailList)
            {
                if (billCode7Layer.BillCodeLayerType.Equals("Block Type"))
                {
                    //before calculate the value,multiply totol meter unit with multiplier value
                    if ((meterUnitCollect.TotalMeterUnit * meterMultiplier) > (sumUnits + item.RateUnit))
                    {
                        result   += (decimal)(item.RateUnit * item.AmountPerUnit);
                        sumUnits += (decimal)item.RateUnit;
                    }
                    else
                    {
                        decimal diffUnits = meterUnitCollect.TotalMeterUnit - sumUnits;
                        result += (decimal)diffUnits * item.AmountPerUnit;
                        if ((diffUnits + sumUnits) == meterUnitCollect.TotalMeterUnit)
                        {
                            return(result);
                        }
                    } //end of else
                }     //end of Block Type condition
                else
                {
                    result = meterUnitCollect.TotalMeterUnit * item.AmountPerUnit;
                }
            } //end of foreach loop
            return(result);
        }     //end of method
Ejemplo n.º 2
0
        private bool SaveMeterUnitCollection(List <NodeMeter> data)
        {
            ErrorList.Clear();
            DateTime fromDate      = dtpfromDate.Value.Date;
            DateTime toDate        = dtptoDate.Value.Date;
            string   transformerId = string.Empty;

            if (!cboTransformer.SelectedValue.Equals("0"))
            {
                transformerId = cboTransformer.SelectedValue.ToString();
            }
            bool checkData = false;

            if (!string.IsNullOrEmpty(transformerId))
            {
                checkData = mbmsEntities.MeterBills.Any(x => EntityFunctions.TruncateTime(x.InvoiceDate) >= fromDate && EntityFunctions.TruncateTime(x.InvoiceDate) <= toDate &&
                                                        x.MeterUnitCollect.TransformerID == transformerId);
            }
            else
            {
                checkData = mbmsEntities.MeterBills.Any(x => EntityFunctions.TruncateTime(x.InvoiceDate) >= fromDate && EntityFunctions.TruncateTime(x.InvoiceDate) <= toDate);
            }

            if (checkData)
            {
                MessageBox.Show("Bill Units can't re-collect because data is already calculated and printed.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            try {
                List <MBMS.DAL.MeterUnitCollect> meterUnitCollectList = new List <MBMS.DAL.MeterUnitCollect>();
                foreach (NodeMeter item in data)
                {
                    MBMS.DAL.MeterUnitCollect meterUnit = new MBMS.DAL.MeterUnitCollect();
                    Customer customerinfo = mbmsEntities.Customers.Where(x => x.CustomerCode == item.nod_csm_id && x.Active == true).SingleOrDefault();//eg >>450-050-545-450-TPYTR05-00000428
                    if (customerinfo == null)
                    {
                        ErrorList.Append("Set customer record for :" + item.nod_csm_id);
                        MessageBox.Show(ErrorList.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return(false);
                    }
                    meterUnit.MeterUnitCollectID = Guid.NewGuid().ToString();
                    meterUnit.CustomerID         = customerinfo.CustomerID;
                    string y = item.nod_bill_from;
                    string m = item.nod_bill_from;
                    string d = item.nod_bill_from;
                    meterUnit.FromDate       = item.nod_bill_from == ""?dtpfromDate.Value:Convert.ToDateTime(y.Substring(0, 4) + "-" + m.Substring(4, 2) + "-" + d.Substring(6, 2));
                    meterUnit.ToDate         = item.nod_bill_to == ""?dtptoDate.Value:Convert.ToDateTime(item.nod_bill_to);
                    meterUnit.TotalMeterUnit = (decimal)item.nod_pres_eng;
                    meterUnit.BillMonth      = (int)item.nod_bill_month;
                    Transformer transformer = mbmsEntities.Transformers.Where(x => x.QuarterID == customerinfo.QuarterID && x.Active == true).SingleOrDefault();
                    if (transformer == null)
                    {
                        ErrorList.Append("Set transformer record for :" + customerinfo.Quarter.QuarterNameInEng);
                        MessageBox.Show(ErrorList.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return(false);
                    }
                    meterUnit.TransformerID = transformer.TransformerID;
                    Pole p = mbmsEntities.Poles.Where(x => x.TransformerID == transformer.TransformerID && x.Active == true).SingleOrDefault();
                    if (p == null)
                    {
                        ErrorList.Append("Set Pole record for :" + customerinfo.Quarter.QuarterNameInEng);
                        MessageBox.Show(ErrorList.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return(false);
                    }
                    meterUnit.PoleID         = p.PoleID;
                    meterUnit.MeterID        = customerinfo.MeterID;
                    meterUnit.GPSX           = Convert.ToDecimal(item.nod_gps_h);
                    meterUnit.GPSY           = Convert.ToDecimal(item.nod_gps_l);
                    meterUnit.MeterStatus    = item.nod_status;
                    meterUnit.OMRModelNo     = item.nod_model;
                    meterUnit.DigitalModelNo = item.nod_model;
                    meterUnit.BillCode       = customerinfo.BillCode7Layer.BillCode7LayerNo.ToString();
                    meterUnit.Active         = true;
                    meterUnit.CreatedDate    = DateTime.Now;
                    meterUnit.CreatedUserID  = UserID;
                    meterUnitCollectList.Add(meterUnit);
                }
                iMeterUnitColleciton.MeterUnitCollectionsProces(meterUnitCollectList);
                return(true);
            }
            catch (Exception ex) {
                MessageBox.Show("Error occur" + ex.Message, "Error");
                return(false);
            }
        }