Exemplo n.º 1
0
        public void AddMatter(string sMattNN, string sRole)
        {
            int idFromNn = PLMatter.GetIDFromNN(sMattNN);

            if (idFromNn.Equals(0))
            {
                return;
            }
            this.AddMatter(idFromNn, PLContactType.GetIDFromNN(sRole));
        }
Exemplo n.º 2
0
        public void AddMatter(string sMattNN)
        {
            int idFromNn = PLMatter.GetIDFromNN(sMattNN);

            if (idFromNn.Equals(0))
            {
                return;
            }
            this.AddMatter(idFromNn, 0);
        }
Exemplo n.º 3
0
 public PCLawConversion()
 {
     try
     {
         this.PL               = new PLLink();
         this.GenInf           = new PLGenInfo();
         this.Lawyer           = new PLLawyer();
         this.User             = new PLUser();
         this.Rate             = new PLRate();
         this.ContactType      = new PLContactType();
         this.DiaryCode        = new PLDiaryCode();
         this.ExpCode          = new PLExpCode();
         this.GLAccts          = new PLGLAccts();
         this.Task             = new PLTask();
         this.GBAcct           = new PLGBAcct();
         this.TBAcct           = new PLTBAcct();
         this.TypeOfLaw        = new PLTypeOfLaw();
         this.Location         = new PLLocationCode();
         this.Department       = new PLDepartment();
         this.RefSource        = new PLRefSource();
         this.Client           = new PLClient();
         this.Contact          = new PLContact();
         this.Matter           = new PLMatter();
         this.Vendor           = new PLVendor();
         this.Bill             = new PLBilling();
         this.WUD              = new PLWUD();
         this.TimeEntry        = new PLTimeEntry();
         this.Trust            = new PLTBEnt();
         this.General          = new PLGBEnt();
         this.Expense          = new PLExpense();
         this.Payable          = new PLPayableEntry();
         this.GJ               = new PLGJEntry();
         this.Diary            = new PLDiary();
         this.SCStageGroup     = new PLSafeCustStageGroup();
         this.SCStage          = new PLSafeCustStage();
         this.SCType           = new PLSafeCustType();
         this.SCStatus         = new PLSafeCustStatus();
         this.SCPacket         = new PLSafeCustPacket();
         this.SCSafeCustRecord = new PLSafeCustEntry();
         this.SCMovements      = new PLSafeCustMovement();
         this.CustomTab        = new PLCustomTab();
     }
     catch (Exception ex)
     {
         int num = (int)MessageBox.Show(ex.Message);
     }
 }
Exemplo n.º 4
0
        public void importGeneralRetainer(bool importClosedMatters)
        {
            if (importClosedMatters)
            {
                PLBilling.m_bAllowEntOnClosedMtr   = true;
                PLTimeEntry.m_bAllowEntOnClosedMtr = true;
                PLExpense.m_bAllowEntOnClosedMtr   = true;
                PLGBEnt.m_bAllowEntOnClosedMtr     = true;
            }

            //gen retainer doesnt have an invoice number or when received > applied. The diff is added as a gen retainer
            DataTable TableGenRetainer = new DataTable("GenRetainer");

            string sSelect = "SELECT * FROM GenRetainer";

            ReadAMTable(ref TableGenRetainer, sSelect);

            for (int nGenRetainer = 0; nGenRetainer < TableGenRetainer.Rows.Count; nGenRetainer++)
            {
                if (string.IsNullOrEmpty(TableGenRetainer.Rows[nGenRetainer]["InvoiceID"].ToString().Trim())) //if there is no invoice, it is a general retainer
                {
                    //add General bank item
                    //exID 1 for oldID and 2 for nickname
                    int bankAcctID = PLGBAcct.GetIDFromExtID1(TableGenRetainer.Rows[nGenRetainer]["BankAcct"].ToString().Trim());
                    if (bankAcctID == 0)
                    {
                        PCLaw.General.BankAcctID = 1;
                    }
                    else
                    {
                        PCLaw.General.BankAcctID = bankAcctID;
                    }
                    PCLaw.General.CheckNum       = TableGenRetainer.Rows[nGenRetainer]["checkno"].ToString().Trim();
                    PCLaw.General.ClientCheckNum = TableGenRetainer.Rows[nGenRetainer]["checkno"].ToString().Trim();
                    PCLaw.General.Date           = int.Parse(TableGenRetainer.Rows[nGenRetainer]["Date"].ToString().Trim());
                    //PCLaw.General.DateEntered = (Int32)(PLDate) rdr["AddingDateTime"];
                    PCLaw.General.EntryGSTCat   = TransactionData.eGST_CAT.NO;
                    PCLaw.General.EntryType     = PLGBEnt.eGBEntryType.GEN_RCPT;
                    PCLaw.General.PaidTo        = "Unapplied Gen Retainer";
                    PCLaw.General.PmtMethodFlag = PLGBEnt.ePmtMethod.Check;
                    PCLaw.General.TotalAmount   = Math.Abs(double.Parse(TableGenRetainer.Rows[nGenRetainer]["Payment"].ToString().Trim()));

                    //if (PCLaw.GenInf.UsingGST)
                    // PCLaw.General.GSTAmount = 0.00;

                    //add retainer allocation
                    PCLaw.General.Alloc.Amount    = Math.Abs(double.Parse(TableGenRetainer.Rows[nGenRetainer]["Payment"].ToString().Trim()));
                    PCLaw.General.Alloc.EntryType = PLGBAlloc.eGBAllocEntryType.GEN_RCPT_RTNR;

                    PCLaw.General.Alloc.Explanation = TableGenRetainer.Rows[nGenRetainer]["Explanation"].ToString().Trim();
                    if (PCLaw.General.Alloc.Explanation == "")
                    {
                        PCLaw.General.Alloc.Explanation = "Conversion - Unapplied GenRet";
                    }

                    PCLaw.General.Alloc.GLID     = PLGLAccts.GetExpRecovID();
                    PCLaw.General.Alloc.MatterID = PLMatter.GetIDFromExtID2(TableGenRetainer.Rows[nGenRetainer]["MatterID"].ToString().Trim());
                    PCLaw.General.AddGBAllocation();

                    PCLaw.General.AddRecord();
                    PCLaw.General.SendLast();
                }

                //if it has an invoice ID but the amount received is greater than the amount applied, the difference is added as a general retainer
                else
                {
                    double difference = Math.Abs(double.Parse(TableGenRetainer.Rows[nGenRetainer]["Payment"].ToString().Trim())) - Math.Abs(double.Parse(TableGenRetainer.Rows[nGenRetainer]["PaymentApplied"].ToString().Trim()));
                    if (difference != 0)
                    {
                        //exID 1 for oldID and 2 for nickname
                        int bankAcctID = PLGBAcct.GetIDFromExtID1(TableGenRetainer.Rows[nGenRetainer]["BankAcct"].ToString().Trim());
                        if (bankAcctID == 0)
                        {
                            PCLaw.General.BankAcctID = 1;
                        }
                        else
                        {
                            PCLaw.General.BankAcctID = bankAcctID;
                        }
                        //PCLaw.General.CheckNum = StringManip.NullToString(rdr["RefNo"]);
                        //PCLaw.General.ClientCheckNum = StringManip.NullToString(rdr["RefNo"]);
                        PCLaw.General.Date = int.Parse(TableGenRetainer.Rows[nGenRetainer]["Date"].ToString().Trim());
                        //PCLaw.General.DateEntered = (Int32)(PLDate) rdr["AddingDateTime"];
                        PCLaw.General.EntryGSTCat   = TransactionData.eGST_CAT.NO;
                        PCLaw.General.EntryType     = PLGBEnt.eGBEntryType.GEN_RCPT;
                        PCLaw.General.PaidTo        = "Unapplied Gen Retainer";
                        PCLaw.General.PmtMethodFlag = PLGBEnt.ePmtMethod.Check;
                        PCLaw.General.TotalAmount   = Math.Abs(double.Parse(TableGenRetainer.Rows[nGenRetainer]["Received"].ToString().Trim()));

                        if (PCLaw.GenInf.UsingGST)
                        {
                            PCLaw.General.GSTAmount = 0.00;
                        }

                        PCLaw.General.Alloc.Amount    = Math.Abs(difference);
                        PCLaw.General.Alloc.EntryType = PLGBAlloc.eGBAllocEntryType.GEN_RCPT_RTNR;

                        if (PCLaw.General.Alloc.Explanation == "")
                        {
                            PCLaw.General.Alloc.Explanation = "Conversion - Unapplied GenRet with Inv";
                        }

                        PCLaw.General.Alloc.GLID     = PLGLAccts.GetExpRecovID();
                        PCLaw.General.Alloc.MatterID = PLMatter.GetIDFromExtID2(TableGenRetainer.Rows[nGenRetainer]["MatterID"].ToString().Trim());
                        PCLaw.General.AddGBAllocation();

                        PCLaw.General.AddRecord();
                        PCLaw.General.SendLast();
                    }
                }
            }
        }
Exemplo n.º 5
0
        public void importPayments(bool importClosedMatters)
        {
            if (importClosedMatters)
            {
                PLBilling.m_bAllowEntOnClosedMtr   = true;
                PLTimeEntry.m_bAllowEntOnClosedMtr = true;
                PLExpense.m_bAllowEntOnClosedMtr   = true;
                PLGBEnt.m_bAllowEntOnClosedMtr     = true;
            }
            try
            {
                //payments must have an invoice number
                DataTable TablePayment = new DataTable("Payment");

                string sSelect = "SELECT * FROM Payment";
                ReadAMTable(ref TablePayment, sSelect);

                for (int nPayment = 0; nPayment < TablePayment.Rows.Count; nPayment++)
                {
                    //exID 1 for oldID and 2 for nickname
                    //int bankAcctID = PLGBAcct.GetIDFromExtID1(TablePayment.Rows[nPayment]["BankAccountID"].ToString().Trim());
                    // if (bankAcctID == 0)
                    // {
                    //   bankAcctID = PLGBAcct.GetIDFromExtID2(TablePayment.Rows[nPayment]["BankAccountID"].ToString().Trim());
                    //  if (bankAcctID == 0)
                    PCLaw.General.BankAcctID = 1;
                    //}
                    //else
                    //PCLaw.General.BankAcctID = bankAcctID;
                    PCLaw.General.CheckNum       = TablePayment.Rows[nPayment]["TransactionID"].ToString().Trim();
                    PCLaw.General.ClientCheckNum = TablePayment.Rows[nPayment]["CheckNumber"].ToString().Trim(); //doesnt matter
                    PCLaw.General.Date           = int.Parse(TablePayment.Rows[nPayment]["EntryDate"].ToString().Trim());
                    PCLaw.General.DateEntered    = PCLaw.General.Date;

                    PCLaw.General.EntryGSTCat = TransactionData.eGST_CAT.NO;
                    PCLaw.General.EntryType   = PLGBEnt.eGBEntryType.GEN_RCPT;

                    if (string.IsNullOrEmpty(TablePayment.Rows[nPayment]["PaidTo"].ToString().Trim()))
                    {
                        PCLaw.General.PaidTo = "Payment Applied";
                    }
                    else
                    {
                        PCLaw.General.PaidTo = TablePayment.Rows[nPayment]["PaidTo"].ToString().Trim();
                    }
                    PCLaw.General.PmtMethodFlag = PLGBEnt.ePmtMethod.Check;
                    //if (PCLaw.GenInf.UsingGST)
                    //PCLaw.General.GSTAmount = 0.00;

                    PCLaw.General.TotalAmount = Math.Abs(double.Parse(TablePayment.Rows[nPayment]["PaymentReceived"].ToString().Trim())); //payments must be a positive number

                    int InvID   = 0;                                                                                                      //oldid
                    int invNum  = 0;                                                                                                      //invoice number
                    int invDate = 0;


                    foreach (Invoice i in invList)
                    {
                        if (i.oldID.Equals(TablePayment.Rows[nPayment]["InvoiceID"].ToString().Trim()))
                        {
                            InvID   = i.newID;
                            invNum  = i.number;//invoice number
                            invDate = i.date;
                            break;
                        }
                    }
                    //   int InvID = PLBilling.GetInvIDfromExtID1(TablePayment.Rows[nPayment]["InvoiceID"].ToString().Trim());//oldid
                    //  int invNum = PLBilling.GetInvNumfromExtID2(TablePayment.Rows[nPayment]["InvoiceNum"].ToString().Trim()); //invoice number
                    //   int invDate = PLBilling.GetInvDatefromExtID2(TablePayment.Rows[nPayment]["InvoiceNum"].ToString().Trim());

                    //add the general allocation

                    PCLaw.General.Alloc.Amount    = PCLaw.General.TotalAmount;
                    PCLaw.General.Alloc.EntryType = PLGBAlloc.eGBAllocEntryType.GEN_RCPT_PMNT;                                      //actual payment

                    PCLaw.General.Alloc.MatterID = PLMatter.GetIDFromNN(TablePayment.Rows[nPayment]["MatterID"].ToString().Trim()); //oldid
                    // if (PCLaw.General.Alloc.MatterID == 0)
                    //   PCLaw.General.Alloc.MatterID = PLMatter.GetIDFromNN(TablePayment.Rows[nPayment]["MatterID"].ToString().Trim());
                    // if (PCLaw.General.Alloc.MatterID == 0)
                    //    PCLaw.General.Alloc.MatterID = PLBilling.GetMattIDfromInvID(InvID);

                    PCLaw.General.Alloc.Explanation = TablePayment.Rows[nPayment]["Explanation"].ToString().Trim();
                    if (string.IsNullOrEmpty(PCLaw.General.Alloc.Explanation))
                    {
                        PCLaw.General.Alloc.Explanation = "Payment for invoice " + invNum;
                    }

                    PCLaw.General.Alloc.GLID = 0;//PLGLAccts.GetIDFromExtID1(TablePayment.Rows[nPayment]["GLAcct"].ToString().Trim()); //nickname
                    // if (PCLaw.General.Alloc.GLID == 0)
                    //    PCLaw.General.Alloc.GLID = PLGLAccts.GetIDFromNN(TablePayment.Rows[nPayment]["GLAcct"].ToString().Trim());
                    PCLaw.General.Alloc.ExplCodeNN = "fd";
                    PCLaw.General.Alloc.InvID      = InvID;
                    PCLaw.General.Alloc.InvDate    = invDate;
                    PCLaw.General.Alloc.InvNumber  = invNum;

                    // MessageBox.Show("MatterID: " + PLMatter.GetIDFromExtID1(TablePayment.Rows[nPayment]["MatterID"].ToString().Trim()).ToString()  +
                    //    " GLID: " + PLGLAccts.GetIDFromExtID1(TablePayment.Rows[nPayment]["GLAcct"].ToString().Trim()).ToString() +
                    //    " InvoiceID: " + InvID.ToString() + " InvNum: " + invNum.ToString() + " InvDate: " + invDate.ToString() + "\r\n" +
                    //    "MatterID: " + PCLaw.General.Alloc.MatterID.ToString() +
                    //     " GLID: " + PCLaw.General.Alloc.GLID.ToString());

                    //Add AR allocation
                    PCLaw.General.RcptARAlloc.Amount      = PCLaw.General.TotalAmount;
                    PCLaw.General.RcptARAlloc.InvID       = InvID;
                    PCLaw.General.RcptARAlloc.ARAllocType = PLGBARAlloc.eAllocType.PAYMENT;

                    PCLaw.General.AddGBAllocation();
                    PCLaw.General.AddRcptARAllocation();

                    PCLaw.General.AddRecord();
                }

                PCLaw.General.SendLast();
            }
            catch (Exception ex3)
            {
                MessageBox.Show(ex3.Message);
            }
        }
Exemplo n.º 6
0
        public void importWriteOffs(bool importClosedMatters)
        {
            DataTable TableWUD = new DataTable("WUD");
            string    sSelect  = "";
            int       nInvID   = 0;


            sSelect = "SELECT * from WUD where amount <> 0.0000";
            ReadAMTable(ref TableWUD, sSelect);

            if (importClosedMatters)
            {
                PLBilling.m_bAllowEntOnClosedMtr   = true;
                PLTimeEntry.m_bAllowEntOnClosedMtr = true;
                PLExpense.m_bAllowEntOnClosedMtr   = true;
                PLGBEnt.m_bAllowEntOnClosedMtr     = true;
            }

            for (int nWUD = 0; nWUD < TableWUD.Rows.Count; nWUD++)
            {
                foreach (Invoice i in invList)
                {
                    if (i.number == int.Parse(TableWUD.Rows[nWUD]["BillID"].ToString().Trim()))
                    {
                        nInvID = i.newID;
                        break;
                    }
                }

                // if (nInvID > 0)
                // {
                if (!string.IsNullOrEmpty(TableWUD.Rows[nWUD]["Date"].ToString().Trim()))
                {
                    int nDate = int.Parse(TableWUD.Rows[nWUD]["Date"].ToString().Trim());
                    if (nDate <= 19820101 || nDate >= 21991231)
                    {
                        nDate = 20061231;
                    }
                    PCLaw.WUD.Date = nDate;
                }
                else
                {
                    PCLaw.WUD.Date = 21991231;     //assign arbitrary date
                }
                if (!string.IsNullOrEmpty(TableWUD.Rows[nWUD]["Explanation"].ToString().Trim()))
                {
                    PCLaw.WUD.Explanation = TableWUD.Rows[nWUD]["Explanation"].ToString().Trim();
                }
                else
                {
                    PCLaw.WUD.Explanation = "Write Off - No Explanation Given";
                }


                PCLaw.WUD.InvID    = nInvID;
                PCLaw.WUD.MatterID = PLMatter.GetIDFromNN(TableWUD.Rows[nWUD]["MatterID"].ToString().Trim());
                //only use this type per the PCLaw dev folks...FEE_WO_ADJ is broken
                PCLaw.WUD.Alloc.EntryType = PLWOAlloc.eWOAllocEntryType.FEE_WO_BADDEBT;

                PCLaw.WUD.TaskNN = "WD";
                if (double.Parse(TableWUD.Rows[nWUD]["Amount"].ToString().Trim()) > 0)
                {
                    PCLaw.WUD.Alloc.Amount = double.Parse(TableWUD.Rows[nWUD]["Amount"].ToString().Trim()) * -1;
                }
                else
                {
                    PCLaw.WUD.Alloc.Amount = double.Parse(TableWUD.Rows[nWUD]["Amount"].ToString().Trim());
                }

                PCLaw.WUD.Alloc.GLID     = PLConvert.PLGLAccts.GetIDFromNN(TableWUD.Rows[nWUD]["GLAcct"].ToString().Trim());
                PCLaw.WUD.Alloc.LawyerID = PLLawyer.GetIDFromNN(TableWUD.Rows[nWUD]["LawyerID"].ToString().Trim());

                PCLaw.WUD.AddWOAllocation();

                PCLaw.WUD.AddRecord();
                PCLaw.WUD.SendLast();

                /*  }
                 * else
                 * {//write off is not associated with any invoice so we create a negative invoice (credit memo)
                 *    MessageBox.Show(TableWUD.Rows[nWUD]["BillID"].ToString().Trim() + " no invoicenum");
                 *    if (!string.IsNullOrEmpty(TableWUD.Rows[nWUD]["Date"].ToString().Trim()))
                 *    {
                 *        int nDate = int.Parse(TableWUD.Rows[nWUD]["Date"].ToString().Trim());
                 *        if (nDate <= 19820101 || nDate >= 21991231)
                 *            nDate = 20061231;
                 *        PCLaw.Bill.Date = nDate;
                 *    }
                 *    else
                 *        PCLaw.Bill.Date = 21991231; //assign arbitrary date
                 *
                 *    //we need to see if amount is negative. If it is, keep the value, if not, make it negative
                 *    if (double.Parse(TableWUD.Rows[nWUD]["Amount"].ToString().Trim()) < 0)
                 *        PCLaw.Bill.Fees = double.Parse(TableWUD.Rows[nWUD]["Amount"].ToString().Trim());
                 *    else
                 *        PCLaw.Bill.Fees = -double.Parse(TableWUD.Rows[nWUD]["Amount"].ToString().Trim());
                 *    PCLaw.Bill.InvoiceNumber = iInvMum;
                 *    iInvMum--;
                 *    iInvMatterID = PLMatter.GetIDFromExtID1(TableWUD.Rows[nWUD]["MatterID"].ToString().Trim());
                 *    PCLaw.Bill.MatterID = iInvMatterID;
                 *    PCLaw.Bill.CollLawyerID = PLMatter.GetRespFromMattID(iInvMatterID);
                 *    PCLaw.Bill.TypeOfLawID = PLMatter.GetTypeofLawFromMattID(iInvMatterID);
                 *    PCLaw.Bill.Alloc.Amount = PCLaw.Bill.Fees;
                 *    PCLaw.Bill.Alloc.LawyerID = PCLaw.Bill.CollLawyerID;
                 *    PCLaw.Bill.AddAllocation();
                 *    PCLaw.Bill.AddRecord(ref iInvID, ref iInvNum, ref iInvDate);
                 *
                 *
                 *    PCLaw.TimeEntry.Date = iInvDate;
                 *    PCLaw.TimeEntry.InvDate = iInvDate;
                 *    PCLaw.TimeEntry.InvNumber = iInvNum;
                 *    PCLaw.TimeEntry.InvoiceID = iInvID;
                 *    PCLaw.TimeEntry.DateEntered = iInvDate;
                 *    PCLaw.TimeEntry.Amount = PCLaw.Bill.Fees;
                 *    PCLaw.TimeEntry.EntryType = PLTimeEntry.eFeeEntryType.FEE_ENTRY;
                 *    PCLaw.TimeEntry.Explanation = "Credit: " + TableWUD.Rows[nWUD]["Explanation"].ToString().Trim();
                 *    PCLaw.TimeEntry.LawyerID = PLMatter.GetRespFromMattID(iInvMatterID);
                 *    PCLaw.TimeEntry.MatterID = iInvMatterID;
                 *    PCLaw.TimeEntry.TaskNN = "BW";
                 *    PCLaw.TimeEntry.AddRecord();
                 *    PCLaw.TimeEntry.SendLast();
                 *
                 * }
                 */
            }
        }
Exemplo n.º 7
0
        //this step includes adding the invoices, allocations and time/expense entries for the invoices
        public void importBills(bool importClosedMatters)
        {
            DataTable TableBills       = new DataTable("Bill");
            DataTable TableAllocations = new DataTable("Allocation");

            string sSelect     = "";
            string allocSelect = "";

            int nInvID   = 0;
            int nInvNum  = 0;
            int nInvDate = 0;

            // bool usingAllocTable = true;


            // InvoiceToMatter itm = null;

            if (importClosedMatters)
            {
                PLBilling.m_bAllowEntOnClosedMtr   = true;
                PLTimeEntry.m_bAllowEntOnClosedMtr = true;
                PLExpense.m_bAllowEntOnClosedMtr   = true;
            }

            //glToID = getGLAcctIDs().ToList();

            sSelect = "SELECT * from Bill";
            ReadAMTable(ref TableBills, sSelect);

            allocSelect = "Select * from Allocation";
            ReadAMTable(ref TableAllocations, allocSelect);

            //add bills and allocations for each bill (add all allocations to the bill before moving to the next bill)
            for (int nBill = 0; nBill < TableBills.Rows.Count; nBill++)
            {
                double allocFees = 0;
                double allocDisb = 0;

                //if (Convert.ToInt32(rdr["void_date"]) > 0)
                // continue; //voided invoice

                //handle interest only invoices?

                //skip invoice is there is no matter or invoice number
                if (!string.IsNullOrEmpty(TableBills.Rows[nBill]["MatterID"].ToString().Trim()) && !string.IsNullOrEmpty(TableBills.Rows[nBill]["BillNumber"].ToString().Trim()))
                {
                    int nDate = int.Parse(TableBills.Rows[nBill]["Date"].ToString().Trim());
                    if (nDate <= 19820101 || nDate >= 21991231)
                    {
                        nDate = 20061231;
                    }
                    PCLaw.Bill.MatterID     = PLMatter.GetIDFromNN(TableBills.Rows[nBill]["MatterID"].ToString().Trim());
                    PCLaw.Bill.CollLawyerID = PLLawyer.GetIDFromNN(TableBills.Rows[nBill]["LawyerID"].ToString().Trim());
                    if (PCLaw.Bill.CollLawyerID == 0)
                    {
                        PCLaw.Bill.CollLawyerID = PLMatter.GetRespFromMattID(PCLaw.Bill.MatterID);
                    }
                    PCLaw.Bill.TypeOfLawID   = PLMatter.GetTypeofLawFromMattID(PCLaw.Bill.MatterID);
                    PCLaw.Bill.InvoiceNumber = Convert.ToInt32(TableBills.Rows[nBill]["BillNumber"].ToString().Trim());
                    PCLaw.Bill.Date          = nDate;
                    PCLaw.Bill.Fees          = Math.Round(double.Parse(TableBills.Rows[nBill]["Fees"].ToString().Trim()), 2) + Math.Round(double.Parse(TableBills.Rows[nBill]["interest"].ToString().Trim()), 2); //what about interest?
                    PCLaw.Bill.Disbs         = Math.Round(double.Parse(TableBills.Rows[nBill]["Disb"].ToString().Trim()), 2);
                    //to avoid problems with firms not using G/L accounting. Bug in PCLaw where Soft Costs are not 0
                    PCLaw.Bill.SoftCosts = 0;
                    // if (!PCLaw.GenInf.UsingGST)
                    //   PCLaw.Bill.PSTFees = Math.Round(double.Parse(TableBills.Rows[nBill]["Taxes"].ToString().Trim()), 2);
                    // else
                    PCLaw.Bill.GSTFees = Math.Round(double.Parse(TableBills.Rows[nBill]["Taxes"].ToString().Trim()), 2);

                    int nCollectID = PLMatter.GetRespFromMattID(PCLaw.Bill.MatterID); //used to create generic entries in case the allocations do not match up with the invoice amounts

                    //bill ready to go, now add allocations
                    for (int nAllocs = 0; nAllocs < TableAllocations.Rows.Count; nAllocs++)
                    {
                        //only add allocations associated with this current bill, otherwise, ignore this allocation

                        if (TableBills.Rows[nBill]["oldID"].ToString().Trim().Equals(TableAllocations.Rows[nAllocs]["BillID"].ToString().Trim(), StringComparison.OrdinalIgnoreCase))
                        {
                            if (int.Parse(TableAllocations.Rows[nAllocs]["TimeExp"].ToString().Trim()) == 0) //time entry
                            {
                                //int nID = PLLawyer.GetIDFromNN(TableAllocations.Rows[nAllocs]["LawyerID"].ToString().Trim());
                                // if (nID.Equals(0))
                                // {
                                //      nID = PLLawyer.GetIDFromNN(TableAllocations.Rows[nAllocs]["LawyerID"].ToString().Trim());
                                // }
                                // if (nID.Equals(0))
                                //     PCLaw.Bill.Alloc.LawyerID = nCollectID;
                                // else
                                // PCLaw.Bill.Alloc.LawyerID = nID;
                                PCLaw.Bill.Alloc.LawyerNN = PLLawyer.GetNNFromID(PLMatter.GetRespFromMattID(PCLaw.Bill.MatterID));
                                double dHours = Math.Round(Convert.ToDouble(TableAllocations.Rows[nAllocs]["QuantityHours"].ToString().Trim()), 2);
                                PCLaw.Bill.Alloc.Amount = Math.Round(Convert.ToDouble(TableAllocations.Rows[nAllocs]["Total"].ToString().Trim()), 2);
                                PCLaw.Bill.Alloc.Hours  = dHours;
                                //PCLaw.Bill.Alloc.Seconds = Convert.ToInt32(dHours * Convert.ToDouble(3600));
                                PCLaw.Bill.Alloc.GLNN = "4000." + PCLaw.Bill.Alloc.LawyerNN;
                                //allocFees = allocFees + PCLaw.Bill.Alloc.Amount;
                                PCLaw.Bill.AddAllocation();
                            }
                            else  //expense record
                            {
                                allocDisb = allocDisb + double.Parse(TableAllocations.Rows[nAllocs]["Total"].ToString().Trim());
                            }
                            //Interest charges must match - TODO
                            //   if (!Math.Round(double.Parse(TableBills.Rows[nBill]["Interest"].ToString().Trim()), 2).Equals(0.0))
                            //    {
                            //       PCLaw.Bill.Alloc.Amount = Math.Round(double.Parse(TableBills.Rows[nBill]["Interest"].ToString().Trim()), 2);
                            //       PCLaw.Bill.Alloc.Hours = 0.0;
                            //       PCLaw.Bill.Alloc.LawyerNN =
                            //           PLLawyer.GetNNFromID(PLMatter.GetRespFromMattID(PCLaw.Bill.MatterID));
                            //       PCLaw.Bill.Alloc.GLNN = "4000." + PCLaw.Bill.Alloc.LawyerNN;
                            //
                            //      PCLaw.Bill.AddAllocation();
                            //  allocFees = allocFees + PCLaw.Bill.Alloc.Amount;
                            //  }
                        } //end if
                    }     //end allocs for



                    double feeDiff = 0.00;
                    //   feeDiff = Math.Round(double.Parse(TableBills.Rows[nBill]["Fees"].ToString().Trim()), 2) + Math.Round(double.Parse(TableBills.Rows[nBill]["Interest"].ToString().Trim()), 2)  - allocFees;
                    //handle mismatch of fees between invoice and sum if individual entries.
                    //need a more graceful way to handle this

                    //if (feeDiff != 0)
                    // {
                    //MessageBox.Show(TableBills.Rows[count]["oldID"].ToString().Trim() + " : " + feeDiff.ToString());
                    //   PCLaw.Bill.Alloc.Amount = feeDiff;
                    //   PCLaw.Bill.Alloc.Hours = 0;
                    //   PCLaw.Bill.Alloc.LawyerID = nCollectID;
                    //PCLaw.Bill.Alloc.GLNN = PCLaw.Bill.CollLawyerID;
                    //  PCLaw.Bill.AddAllocation();
                    // }
                    //handle mismatch of disb between invoice and sum if individual entries. - currently there is only one disb per bill so it will always match
                    //   double disbDiff = Math.Round(double.Parse(TableBills.Rows[nBill]["Disb"].ToString().Trim()), 2) - allocDisb;
                    //  if (disbDiff != 0)
                    //     disbDiff = PCLaw.Bill.Disbs - allocDisb;



                    //add the bill
                    int     matterID = PCLaw.Bill.MatterID; //saved for use later on time and expense entries
                    Invoice i        = new Invoice();
                    PCLaw.Bill.bAutoCreateCharges = false;
                    PCLaw.Bill.ExternalID_1       = TableBills.Rows[nBill]["OldID"].ToString().Trim();
                    PCLaw.Bill.ExternalID_2       = TableBills.Rows[nBill]["BillNumber"].ToString().Trim();

                    PCLaw.Bill.AddRecord(ref nInvID, ref nInvNum, ref nInvDate);
                    i.newID  = nInvID;
                    i.number = nInvNum;
                    i.oldID  = TableBills.Rows[nBill]["BillID"].ToString().Trim();
                    i.date   = nInvDate;
                    invList.Add(i);

                    //allocs and bill done, now we add the time and expense entries associated with them
                    //bill ready to go, now add allocations
                    for (int allocs = 0; allocs < TableAllocations.Rows.Count; allocs++)
                    {
                        //only time/fee entries (allocations) associated with this current bill, otherwise, ignore this entry
                        if (TableBills.Rows[nBill]["BillID"].ToString().Trim().Equals(TableAllocations.Rows[allocs]["BillID"].ToString().Trim(), StringComparison.OrdinalIgnoreCase))
                        {
                            if (int.Parse(TableAllocations.Rows[allocs]["TimeExp"].ToString().Trim()) == 0) //time entry
                            {
                                PCLaw.TimeEntry.InvoiceID   = nInvID;
                                PCLaw.TimeEntry.InvNumber   = nInvNum;
                                PCLaw.TimeEntry.Date        = int.Parse(TableAllocations.Rows[allocs]["EntryDate"].ToString().Trim());
                                PCLaw.TimeEntry.DateEntered = int.Parse(TableAllocations.Rows[allocs]["EntryDate"].ToString().Trim());

                                double dur = Convert.ToDouble(TableAllocations.Rows[allocs]["QuantityHours"].ToString().Trim());
                                PCLaw.TimeEntry.Hours = dur;

                                if (double.Parse(TableAllocations.Rows[allocs]["QuantityHours"].ToString().Trim()) == 0.0000)
                                {
                                    PCLaw.TimeEntry.EntryType = PLTimeEntry.eFeeEntryType.FEE_ENTRY;
                                }
                                else
                                {
                                    PCLaw.TimeEntry.EntryType = PLTimeEntry.eFeeEntryType.TimeEnt;
                                }

                                PCLaw.TimeEntry.MatterID = matterID;

                                int taskID = 0;
                                //if (!string.IsNullOrEmpty(TableAllocations.Rows[allocs]["CodeID"].ToString().Trim()))
                                //    taskID = PLTask.GetIDFromNN(TableAllocations.Rows[allocs]["CodeID"].ToString().Trim());
                                // if (taskID == 0)
                                // {
                                taskID = PLTask.GetIDFromNN("BW");
                                // if (taskID == 0)
                                // {
                                //      PCLaw.TimeEntry.TaskNN = "BW";
                                ////    if (PCLaw.TimeEntry.TaskID.Equals(0))
                                //   {
                                //      PCLaw.Task.Name = "Billable Work";
                                //      PCLaw.Task.NickName = "BW";
                                //      PCLaw.Task.Category = PLTask.eCATEGORY.NON_BILLABLE;
                                //     PCLaw.Task.AddRecord();
                                //     PCLaw.Task.SendLast();
                                //     PCLaw.TimeEntry.TaskNN = "BW";
                                // }
                                //}
                                //}
                                //else
                                PCLaw.TimeEntry.TaskID = taskID;

                                string descr = "";
                                if (!string.IsNullOrEmpty(TableAllocations.Rows[allocs]["Description"].ToString().Trim()))
                                {
                                    descr = TableAllocations.Rows[allocs]["Description"].ToString().Trim();
                                }
                                if (descr.Equals(""))
                                {
                                    descr = "Converted time entry, no explanaion provided";
                                }
                                PCLaw.TimeEntry.Explanation = descr;

                                int lawyerID = PLLawyer.GetIDFromNN(TableAllocations.Rows[allocs]["LawyerID"].ToString().Trim());
                                if (lawyerID.Equals(0))
                                {
                                    PCLaw.TimeEntry.LawyerNN = PLLawyer.GetNNFromID(PLMatter.GetRespFromMattID(matterID));
                                }
                                else
                                {
                                    PCLaw.TimeEntry.LawyerID = lawyerID;
                                }

                                if (double.Parse(TableAllocations.Rows[allocs]["Rate"].ToString().Trim()) == 0.0)
                                {
                                    try
                                    {
                                        if (Convert.ToDouble(TableAllocations.Rows[allocs]["Total"].ToString().Trim()) != 0 && dur != 0)
                                        {
                                            PCLaw.TimeEntry.Rate = Math.Round(Convert.ToDouble(TableAllocations.Rows[allocs]["Total"].ToString().Trim()) / dur, 2);
                                        }
                                    }
                                    catch (Exception ex1)
                                    {
                                        PCLaw.TimeEntry.Rate = double.Parse(TableAllocations.Rows[allocs]["Rate"].ToString().Trim());
                                    }
                                }
                                else
                                {
                                    PCLaw.TimeEntry.Rate = double.Parse(TableAllocations.Rows[allocs]["Rate"].ToString().Trim());
                                }
                                PCLaw.TimeEntry.Amount = Convert.ToDouble(TableAllocations.Rows[allocs]["Total"].ToString().Trim());


                                PCLaw.TimeEntry.AddRecord();
                            }    //end time entries
                            else //expense entry
                            {
                                PCLaw.Expense.InvoiceID     = nInvID;
                                PCLaw.Expense.InvoiceNumber = nInvNum;

                                PCLaw.Expense.Date = int.Parse(TableAllocations.Rows[allocs]["EntryDate"].ToString().Trim());

                                PCLaw.Expense.MatterID = matterID;

                                string descr = "";
                                if (!string.IsNullOrEmpty(TableAllocations.Rows[allocs]["Description"].ToString().Trim()))
                                {
                                    descr = TableAllocations.Rows[allocs]["Description"].ToString().Trim();
                                }
                                if (descr.Equals(""))
                                {
                                    descr = "Converted expense, no explanaion provided";
                                }

                                PCLaw.Expense.Explanation = descr;

                                int explID = 0;
                                if (!string.IsNullOrEmpty(TableAllocations.Rows[allocs]["CodeID"].ToString().Trim()))
                                {
                                    explID = PLExpCode.GetIDFromNN(TableAllocations.Rows[allocs]["CodeID"].ToString().Trim());
                                }
                                if (explID == 0)
                                {
                                    PCLaw.Expense.ExplCodeID = PLExpCode.GetIDFromNN("A111"); //default code "other"
                                }
                                else
                                {
                                    PCLaw.Expense.ExplCodeID = explID;
                                }

                                PCLaw.Expense.Quantity   = Convert.ToDouble(TableAllocations.Rows[allocs]["QuantityHours"].ToString().Trim());
                                PCLaw.Expense.Rate       = Convert.ToDouble(TableAllocations.Rows[allocs]["Rate"].ToString().Trim());
                                PCLaw.Expense.Amount     = Convert.ToDouble(TableAllocations.Rows[allocs]["Total"].ToString().Trim());
                                PCLaw.Expense.IsSoftCost = false;

                                if (string.IsNullOrEmpty(TableAllocations.Rows[allocs]["ExpensePaidTo"].ToString().Trim()))
                                {
                                    PCLaw.Expense.PaidTo = "Converted - Billed Expenses";
                                }
                                else
                                {
                                    PCLaw.Expense.PaidTo = TableAllocations.Rows[allocs]["ExpensePaidTo"].ToString().Trim();
                                }
                                if (!string.IsNullOrEmpty(TableAllocations.Rows[allocs]["GLAcctID"].ToString().Trim()))
                                {
                                    int id = PLConvert.PLGLAccts.GetIDFromExtID2(TableAllocations.Rows[allocs]["GLAcctID"].ToString().Trim());
                                    if (id == 0)
                                    {
                                        PCLaw.Expense.GLNN = "5210";
                                    }
                                    else
                                    {
                                        PCLaw.Expense.GLNN = PLConvert.PLGLAccts.GetNNFromID(id);
                                    }
                                }
                                else
                                {
                                    PCLaw.Expense.GLNN = "5210";
                                }


                                PCLaw.Expense.AddRecord();
                            } //end expense entries (else)
                        }     //end outer if
                    }         //end time/expense for

                    //if time and expense entries do not match bill, we add a generic entry to make them even

                    /*
                     *  if (feeDiff != 0.00)
                     *  {
                     *      PCLaw.TimeEntry.Amount = feeDiff;
                     *      feeDiff = 0.0;
                     *
                     *      PCLaw.TimeEntry.InvDate = nInvDate;
                     *      PCLaw.TimeEntry.InvoiceID = nInvID;
                     *      PCLaw.TimeEntry.InvNumber = nInvNum;
                     *      PCLaw.TimeEntry.Date = nInvDate;
                     *      PCLaw.TimeEntry.Seconds = 0;
                     *      PCLaw.TimeEntry.EntryType = PLTimeEntry.eFeeEntryType.FEE_ENTRY;
                     *      PCLaw.TimeEntry.MatterID = matterID;
                     *      PCLaw.TimeEntry.TaskNN = "BW";
                     *
                     *      if (PCLaw.TimeEntry.TaskID.Equals(0))
                     *      {
                     *          PCLaw.Task.Name = "Billable Work";
                     *          PCLaw.Task.NickName = "BW";
                     *          PCLaw.Task.Category = PLTask.eCATEGORY.NON_BILLABLE;
                     *          PCLaw.Task.AddRecord();
                     *          PCLaw.Task.SendLast();
                     *          PCLaw.TimeEntry.TaskNN = "BW";
                     *      }
                     *
                     *      PCLaw.TimeEntry.Explanation = "Time Offset - bill mismatch";
                     *      PCLaw.TimeEntry.LawyerID = nCollectID;
                     *
                     *      PCLaw.TimeEntry.AddRecord();
                     *  }
                     *
                     *  if (disbDiff != 0)
                     *  {
                     *      PCLaw.Expense.InvDate = nInvDate;
                     *      PCLaw.Expense.InvoiceID = nInvID;
                     *      PCLaw.Expense.InvoiceNumber = nInvNum;
                     *      PCLaw.Expense.Date = nInvDate;
                     *      PCLaw.Expense.MatterID = matterID;
                     *      PCLaw.Expense.IsSoftCost = false;
                     *      PCLaw.Expense.Explanation = "Conversion Repair";
                     *      PCLaw.Expense.Amount = disbDiff;
                     *      disbDiff = 0.0;
                     *      PCLaw.Expense.PaidTo = "Expense Offset - Billed Expenses";
                     *      PCLaw.Expense.GLNN = "5210";
                     *      PCLaw.Expense.AddRecord();
                     *  }
                     *
                     *
                     *  if (!Math.Round(double.Parse(TableBills.Rows[nBill]["interest"].ToString().Trim()), 2).Equals(0.0))
                     *  {
                     *      PCLaw.TimeEntry.Amount =
                     *          Math.Round(double.Parse(TableBills.Rows[nBill]["interest"].ToString().Trim()), 2);
                     *
                     *      PCLaw.TimeEntry.InvDate = nInvDate;
                     *      PCLaw.TimeEntry.InvoiceID = nInvID;
                     *      PCLaw.TimeEntry.InvNumber = nInvNum;
                     *      PCLaw.TimeEntry.Date = nInvDate;
                     *      PCLaw.TimeEntry.Seconds = 0;
                     *      PCLaw.TimeEntry.EntryType = PLTimeEntry.eFeeEntryType.FEE_ENTRY;
                     *      PCLaw.TimeEntry.MatterID = matterID;
                     *      PCLaw.TimeEntry.TaskNN = "BW";
                     *
                     *      if (PCLaw.TimeEntry.TaskID.Equals(0))
                     *      {
                     *          PCLaw.Task.Name = "Billable Work";
                     *          PCLaw.Task.NickName = "BW";
                     *          PCLaw.Task.Category = PLTask.eCATEGORY.NON_BILLABLE;
                     *          PCLaw.Task.AddRecord();
                     *          PCLaw.Task.SendLast();
                     *          PCLaw.TimeEntry.TaskNN = "BW";
                     *      }
                     *
                     *      PCLaw.TimeEntry.Explanation = "Interest Charged on Invoice " + nInvNum.ToString();
                     *      PCLaw.TimeEntry.LawyerNN = PLLawyer.GetNNFromID(PLMatter.GetRespFromMattID(matterID));
                     *
                     *      PCLaw.TimeEntry.AddRecord();
                     *  }
                     *
                     */
                } //end if
            }     //end bills for


            PCLaw.TimeEntry.SendLast();
            PCLaw.Expense.SendLast();
        }
Exemplo n.º 8
0
 public void AddMatter(string sMattNN)
 {
     this.AddMatter(PLMatter.GetIDFromNN(sMattNN));
 }
Exemplo n.º 9
0
        }//end method

        private void addPhoneCalls()
        {
            int      nPhone = 0;
            DateTime DateStart;
            DateTime DateEnd;
            TimeSpan Duration;
            //int nDateStart = 0;
            int nStartTime = 0;
            int nEndTime   = 0;
            int nValue     = 0;

            DataTable Table   = new DataTable("Phone");
            string    sSelect = "SELECT * FROM [PhoneCall]";

            ReadAMTable(ref Table, sSelect);

            for (nPhone = 0; nPhone < Table.Rows.Count; nPhone++)
            {
                PCLaw.Diary.EntryType        = PLConvert.PLDiary.eType.Call;
                PCLaw.Diary.CallDirectionOut = bool.Parse(Table.Rows[nPhone]["OutgoingCall"].ToString().Trim());

                PCLaw.Diary.CallContactName = Table.Rows[nPhone]["CallerName"].ToString().Trim();
                PCLaw.Diary.CallPhoneNumber = Table.Rows[nPhone]["CallerNumber"].ToString().Trim();

                int nDate = int.Parse(Table.Rows[nPhone]["DueDate"].ToString().Trim()); //see appointment for same code with notes
                if (nDate < 19820101)
                {
                    nDate = 19820101;
                }
                DateStart           = Convert.ToDateTime(Table.Rows[nPhone]["StartTime"].ToString());
                PCLaw.Diary.DueDate = nDate;

                PCLaw.Diary.EnteredDate = int.Parse(Table.Rows[nPhone]["EnteredDate"].ToString().Trim());

                nStartTime            = DateStart.Hour * 100 + DateStart.Minute; //see appointment for same code with notes hhmm
                PCLaw.Diary.StartTime = nStartTime;

                if (!string.IsNullOrEmpty(Table.Rows[nPhone]["EndTime"].ToString())) //shouldnt ever be null or empty
                {
                    if (int.Parse(Table.Rows[nPhone]["EndTime"].ToString()) != 0)    //should be zero if we are using duration (like for splits)
                    {
                        DateEnd  = Convert.ToDateTime(Table.Rows[nPhone]["EndTime"].ToString());
                        nEndTime = DateEnd.Hour * 100 + DateEnd.Minute;

                        Duration = DateEnd - DateStart;

                        PCLaw.Diary.Duration = Duration.Days * 24 + Duration.Hours + Duration.Minutes / 60; //see appointment for same code with notes
                    }
                }

                else
                {
                    PCLaw.Diary.Duration = double.Parse(Table.Rows[nPhone]["Duration"].ToString());
                }


                if (PCLaw.Diary.Duration < 0)
                {
                    PCLaw.Diary.Duration = 1.0 / 60.0; //one minute
                }
                if (!string.IsNullOrEmpty(Table.Rows[nPhone]["Description"].ToString().Trim()))
                {
                    PCLaw.Diary.Description = Table.Rows[nPhone]["Description"].ToString().Trim();
                }
                else
                {
                    PCLaw.Diary.Description = "Converted Call - No Description available";
                }

                switch (Convert.ToInt32(Table.Rows[nPhone]["CallActionTaken"].ToString().Trim()))
                {
                // 1 = spoke, 2 = Left Message, 3 = No Answer, 4 = Busy, 5 = Voice Mail
                case 1:
                    PCLaw.Diary.PhoneCallAction = PLConvert.PLDiary.eCallAction.Spoke;
                    break;

                case 2:
                    PCLaw.Diary.PhoneCallAction = PLConvert.PLDiary.eCallAction.LeftMsg;
                    break;

                case 3:
                    PCLaw.Diary.PhoneCallAction = PLConvert.PLDiary.eCallAction.NoAnswer;
                    break;

                case 4:
                    PCLaw.Diary.PhoneCallAction = PLConvert.PLDiary.eCallAction.Busy;
                    break;

                case 5:
                    PCLaw.Diary.PhoneCallAction = PLConvert.PLDiary.eCallAction.VoiceMail;
                    break;
                }//end switch

                //did they call them back?
                if (!string.IsNullOrEmpty(Table.Rows[nPhone]["PhoneCallReturned"].ToString().Trim()))
                {
                    PCLaw.Diary.PhoneCallReturnedCall = bool.Parse(Table.Rows[nPhone]["PhoneCallReturned"].ToString().Trim());
                }
                else
                {
                    PCLaw.Diary.PhoneCallReturnedCall = false;
                }

                if (!string.IsNullOrEmpty(Table.Rows[nPhone]["IsUrgent"].ToString().Trim()))
                {
                    if (bool.Parse(Table.Rows[nPhone]["IsUrgent"].ToString().Trim()))
                    {
                        PCLaw.Diary.Priority = PLConvert.PLDiary.ePriority.High;
                    }
                    else
                    {
                        PCLaw.Diary.Priority = PLConvert.PLDiary.ePriority.Normal;
                    }
                }//end if
                else
                {
                    PCLaw.Diary.Priority = PLConvert.PLDiary.ePriority.Normal;
                }

                if (bool.Parse(Table.Rows[nPhone]["Completed"].ToString().Trim()))
                {
                    PCLaw.Diary.Completed      = true;
                    PCLaw.Diary.CompletionDate = int.Parse(Table.Rows[nPhone]["CompletedDate"].ToString().Trim());
                }
                else
                {
                    PCLaw.Diary.Completed = false;
                }

                PCLaw.Diary.MatterID = PLMatter.GetIDFromExtID1(Table.Rows[nPhone]["MatterID"].ToString().Trim());
                if (PCLaw.Diary.MatterID == 0) //not found and is required....diary entry not added
                {
                    PCLaw.Diary.Clear();
                    continue;
                }//end if

                //add users to diary entry
                string[] users         = Table.Rows[nPhone]["UserID"].ToString().Split('|');
                bool     isMessageRead = true;
                bool     hasUser       = false;
                foreach (string user in users)
                {
                    nValue = PLUser.GetIDFromNN(user.Trim());
                    if (nValue != 0)
                    {
                        PCLaw.Diary.AddUser(nValue, isMessageRead);
                        hasUser = true;
                    } //end if
                }     //end foreach

                //add contacts to diary entry
                string[] contacts = Table.Rows[nPhone]["ContactID"].ToString().Split('|');
                foreach (string contact in contacts)
                {
                    nValue = PLContact.GetIDFromExtID1(contact.Trim());
                    if (nValue != 0)
                    {
                        PCLaw.Diary.AddContact(nValue);
                    }
                }//end foreach


                if (!hasUser)//at least one user is required so if we have none, assign it to ADMIN
                {
                    nValue = PLUser.GetIDFromNN("ADMIN");
                    PCLaw.Diary.AddUser(nValue, isMessageRead);
                }//end if

                PCLaw.Diary.AddRecord();
            } //end for
            PCLaw.Diary.SendLast();
        }     //end method
Exemplo n.º 10
0
        }//end method

        private void addCalendarEntries()
        {
            int      nCalendar = 0;
            TimeSpan Duration;
            int      nDate = 0;
            //int nDateEnd = 0;
            int nTimeStart = 0;
            int nValue     = 0;

            DataTable Table   = new DataTable("Appointment");
            string    sSelect = "SELECT * FROM [Appointment]";

            ReadAMTable(ref Table, sSelect);

            for (nCalendar = 0; nCalendar < Table.Rows.Count; nCalendar++)
            {
                PCLaw.Diary.IsRecurringEntry = bool.Parse(Table.Rows[nCalendar]["IsRecurring"].ToString());

                nDate = int.Parse(Table.Rows[nCalendar]["EnteredDate"].ToString().Trim());
                if (nDate < 19820101) //if the date is before pclaw's min level, make it the min
                {
                    nDate = 19820101;
                }
                PCLaw.Diary.EnteredDate = nDate;

                nDate = int.Parse(Table.Rows[nCalendar]["DueDate"].ToString().Trim());
                if (nDate < 19820101)
                {
                    nDate = 19820101;
                }
                PCLaw.Diary.DueDate = nDate;

                DateTime DateEnd;
                DateTime DateStart;

                if (double.Parse(Table.Rows[nCalendar]["Duration"].ToString()) == 0)
                {
                    DateEnd              = Convert.ToDateTime(Table.Rows[nCalendar]["DueDate"].ToString().Insert(6, "-").Insert(4, "-"));
                    DateStart            = Convert.ToDateTime(Table.Rows[nCalendar]["StartDate"].ToString().Insert(6, "-").Insert(4, "-"));
                    Duration             = DateEnd - DateStart; //duration of the event
                    PCLaw.Diary.Duration = Duration.Days * 24 + Duration.Hours + Duration.Minutes / 60;
                }
                else
                {
                    Duration             = TimeSpan.FromHours(double.Parse(Table.Rows[nCalendar]["Duration"].ToString()));
                    PCLaw.Diary.Duration = double.Parse(Duration.ToString());
                }


                if (PCLaw.Diary.IsRecurringEntry)//if its recurring, we have work to do!
                {
                    PCLaw.Diary.RecurringStartDate = int.Parse(Table.Rows[nCalendar]["RecurringStartDate"].ToString().Trim());
                    PCLaw.Diary.RecurringEndDate   = int.Parse(Table.Rows[nCalendar]["RecurringEndDate"].ToString().Trim());

                    PCLaw.Diary.RecurringRepeatUnit = PLDiary.eRepeatUnit.CalendarDay;

                    //1) Daily requires a number od days before repeating (rDaysDaily)
                    //2) Monthly requires:
                    //   a) Which day of the month to repeat (rDayOfMonth) - OR-
                    //   b) Which week of the month (rWeekOfMonth) AND which day of the week to repeat (rDayOfWeek)
                    //3) Quarterly requires a day of the month (rDayOfMonth) AND how many months before it repeats (rMonthsQuarterly)
                    //4) Weekly requires a day of the week (rDayOfWeek)
                    //5) Anually requires a month of the year (rMonthsOfYear) AND
                    //   a) Day of the month (rDayOfMonth) OR
                    //   b) Week of month (rWeekOfMonth) AND day of week (rDaysOfWeek)
                    //Frequency means how often to make the appointment

                    switch (int.Parse(Table.Rows[nCalendar]["RecurringType"].ToString()))
                    {
                    case 1:       //Daily
                        PCLaw.Diary.RecurringRepeatUnit = PLDiary.eRepeatUnit.CalendarDay;
                        PCLaw.Diary.RecurringFreq       = int.Parse(Table.Rows[nCalendar]["rDaysDaily"].ToString());
                        break;

                    case 2:     //Monthly
                        PCLaw.Diary.RecurringRepeatUnit = PLDiary.eRepeatUnit.Month;

                        if (int.Parse(Table.Rows[nCalendar]["rDayOfMonth"].ToString()) != 0)
                        {
                            PCLaw.Diary.RecurringDayOfMonth = int.Parse(Table.Rows[nCalendar]["rDayOfMonth"].ToString());
                        }
                        else
                        {
                            if (int.Parse(Table.Rows[nCalendar]["rWeekOfMonth"].ToString()) != 0)
                            {
                                PCLaw.Diary.RecurringWeekOfMonth = int.Parse(Table.Rows[nCalendar]["rWeekOfMonth"].ToString());
                            }

                            if (PCLaw.Diary.RecurringWeekOfMonth == 0)
                            {
                                PCLaw.Diary.RecurringWeekOfMonth = 1;
                            }

                            switch (int.Parse(Table.Rows[nCalendar]["rDayOfWeek"].ToString()))
                            {
                            case 1:
                                PCLaw.Diary.RecurringDayOfWeek = PLConvert.PLDiary.eDay.Sun;
                                break;

                            case 2:
                                PCLaw.Diary.RecurringDayOfWeek = PLConvert.PLDiary.eDay.Non;
                                break;

                            case 3:
                                PCLaw.Diary.RecurringDayOfWeek = PLConvert.PLDiary.eDay.Tue;
                                break;

                            case 4:
                                PCLaw.Diary.RecurringDayOfWeek = PLConvert.PLDiary.eDay.Wed;
                                break;

                            case 5:
                                PCLaw.Diary.RecurringDayOfWeek = PLConvert.PLDiary.eDay.Thur;
                                break;

                            case 6:
                                PCLaw.Diary.RecurringDayOfWeek = PLConvert.PLDiary.eDay.Fri;
                                break;

                            case 7:
                                PCLaw.Diary.RecurringDayOfWeek = PLConvert.PLDiary.eDay.Sat;
                                break;

                            default:
                                PCLaw.Diary.RecurringDayOfWeek = PLConvert.PLDiary.eDay.Non;
                                break;
                            }                                                             //end switch
                        }                                                                 //end else
                        decimal month = Duration.Days / 30;                               // there are 30 days in an average month so days/30 = months
                        PCLaw.Diary.RecurringFreq = Convert.ToInt32(Math.Ceiling(month)); //ceiling because we need an int here
                        if (PCLaw.Diary.RecurringFreq < 1)
                        {
                            PCLaw.Diary.RecurringFreq = 1;
                        }
                        break;

                    case 3:     //Quarterly
                        PCLaw.Diary.RecurringRepeatUnit = PLDiary.eRepeatUnit.Month;
                        PCLaw.Diary.RecurringDayOfMonth = int.Parse(Table.Rows[nCalendar]["rDayOfMonth"].ToString());
                        PCLaw.Diary.RecurringFreq       = int.Parse(Table.Rows[nCalendar]["rMonthsQuarterly"].ToString());
                        break;

                    case 4:     //Weekly
                        PCLaw.Diary.RecurringRepeatUnit = PLDiary.eRepeatUnit.Week;

                        switch (int.Parse(Table.Rows[nCalendar]["rDayOfWeek"].ToString()))
                        {
                        case 1:
                            PCLaw.Diary.RecurringDayOfWeek = PLConvert.PLDiary.eDay.Sun;
                            break;

                        case 2:
                            PCLaw.Diary.RecurringDayOfWeek = PLConvert.PLDiary.eDay.Non;        //to do - change that type in plconvert
                            break;

                        case 3:
                            PCLaw.Diary.RecurringDayOfWeek = PLConvert.PLDiary.eDay.Tue;
                            break;

                        case 4:
                            PCLaw.Diary.RecurringDayOfWeek = PLConvert.PLDiary.eDay.Wed;
                            break;

                        case 5:
                            PCLaw.Diary.RecurringDayOfWeek = PLConvert.PLDiary.eDay.Thur;
                            break;

                        case 6:
                            PCLaw.Diary.RecurringDayOfWeek = PLConvert.PLDiary.eDay.Fri;
                            break;

                        case 7:
                            PCLaw.Diary.RecurringDayOfWeek = PLConvert.PLDiary.eDay.Sat;
                            break;

                        default:
                            PCLaw.Diary.RecurringDayOfWeek = PLConvert.PLDiary.eDay.Non;
                            break;
                        }                                 //end switch

                        decimal week = Duration.Days / 4; //there are 4 weeks in a month so days/4 = weeks
                        PCLaw.Diary.RecurringFreq = Convert.ToInt32(Math.Ceiling(week));
                        if (PCLaw.Diary.RecurringFreq < 1)
                        {
                            PCLaw.Diary.RecurringFreq = 1;
                        }
                        break;

                    case 5:     //Annually
                        PCLaw.Diary.RecurringRepeatUnit = PLDiary.eRepeatUnit.Year;

                        PCLaw.Diary.RecurringMonthOfYear = int.Parse(Table.Rows[nCalendar]["rMonthsOfYear"].ToString());

                        if (int.Parse(Table.Rows[nCalendar]["rDayOfMonth"].ToString()) != 0)
                        {
                            PCLaw.Diary.RecurringDayOfMonth = int.Parse(Table.Rows[nCalendar]["rDayOfMonth"].ToString());
                        }
                        else
                        {
                            PCLaw.Diary.RecurringWeekOfMonth = int.Parse(Table.Rows[nCalendar]["rWeekOfMonth"].ToString());

                            switch (int.Parse(Table.Rows[nCalendar]["rDayOfWeek"].ToString()))
                            {
                            case 1:
                                PCLaw.Diary.RecurringDayOfWeek = PLConvert.PLDiary.eDay.Sun;
                                break;

                            case 2:
                                PCLaw.Diary.RecurringDayOfWeek = PLConvert.PLDiary.eDay.Non;
                                break;

                            case 3:
                                PCLaw.Diary.RecurringDayOfWeek = PLConvert.PLDiary.eDay.Tue;
                                break;

                            case 4:
                                PCLaw.Diary.RecurringDayOfWeek = PLConvert.PLDiary.eDay.Wed;
                                break;

                            case 5:
                                PCLaw.Diary.RecurringDayOfWeek = PLConvert.PLDiary.eDay.Thur;
                                break;

                            case 6:
                                PCLaw.Diary.RecurringDayOfWeek = PLConvert.PLDiary.eDay.Fri;
                                break;

                            case 7:
                                PCLaw.Diary.RecurringDayOfWeek = PLConvert.PLDiary.eDay.Sat;
                                break;

                            default:
                                PCLaw.Diary.RecurringDayOfWeek = PLConvert.PLDiary.eDay.Non;
                                break;
                            } //end switch
                        }     //end else

                        decimal year = Duration.Days / 365;
                        PCLaw.Diary.RecurringFreq = Convert.ToInt32(Math.Ceiling(year));
                        if (PCLaw.Diary.RecurringFreq < 1)
                        {
                            PCLaw.Diary.RecurringFreq = 1;
                        }
                        break;
                    }//end switch with no default on purpose

                    switch (int.Parse(Table.Rows[nCalendar]["HolidayRecurringBehavior"].ToString()))
                    {
                    case 1:
                        PCLaw.Diary.RecurringAdjust = PLDiary.eAdjust.NextBusDay;
                        break;

                    case 2:
                        PCLaw.Diary.RecurringAdjust = PLDiary.eAdjust.PrevBusDay;
                        break;

                    case 3:
                        PCLaw.Diary.RecurringAdjust = PLDiary.eAdjust.SameDay;
                        break;

                    case 4:
                        PCLaw.Diary.RecurringAdjust = PLDiary.eAdjust.CancelEntry;
                        break;
                    } //end switch
                }     //end recurring if

                switch (int.Parse(Table.Rows[nCalendar]["EntryType"].ToString()))
                {
                case 0:
                    PCLaw.Diary.EntryType = PLDiary.eType.Holiday;
                    break;

                case 1:
                    PCLaw.Diary.EntryType = PLDiary.eType.Appointment;
                    break;

                case 2:
                    PCLaw.Diary.EntryType = PLDiary.eType.TODO;
                    break;
                }//end switch

                if (!string.IsNullOrEmpty(Table.Rows[nCalendar]["Description"].ToString()))
                {
                    PCLaw.Diary.Description = Table.Rows[nCalendar]["Description"].ToString();
                }
                else
                {
                    PCLaw.Diary.Description = "Converted Event - No Description Available";
                }

                if (PCLaw.Diary.EntryType == PLDiary.eType.Appointment)
                {
                    //pclaw needs the time in this format hhmm as an int
                    //nTimeStart = DateStart.Hour * 100 + DateStart.Minute;
                    nTimeStart = int.Parse(Table.Rows[nCalendar]["StartTime"].ToString());
                    if (nTimeStart < 700 || nTimeStart > 2359)    //why would this appointment happen before 7am or be greater than 11:59?
                    {
                        nTimeStart = 700;
                    }

                    PCLaw.Diary.StartTime = nTimeStart;
                    //duration needs to be an double and is in hours which is why the funky math
                    //PCLaw.Diary.Duration = Duration.Days * 24 + Duration.Hours + Duration.Minutes / 60;
                }//end if

                if (PCLaw.Diary.Duration <= 0) //duration cant be zero or negative
                {
                    PCLaw.Diary.Duration = 0.5;
                }

                switch (int.Parse(Table.Rows[nCalendar]["Priority"].ToString()))
                {
                case 0:
                    PCLaw.Diary.Priority = PLDiary.ePriority.Normal;
                    break;

                case 1:
                    PCLaw.Diary.Priority = PLDiary.ePriority.High;
                    break;

                case 2:
                    PCLaw.Diary.Priority = PLDiary.ePriority.Low;
                    break;

                default:
                    PCLaw.Diary.Priority = PLDiary.ePriority.Normal;
                    break;
                }//end switch

                if (PCLaw.Diary.EntryType == PLDiary.eType.TODO)
                {
                    if (!string.IsNullOrEmpty(Table.Rows[nCalendar]["Completed"].ToString()))
                    {
                        PCLaw.Diary.Completed = bool.Parse(Table.Rows[nCalendar]["Completed"].ToString());
                    }
                    else
                    {
                        PCLaw.Diary.Completed = false;
                    }
                    if (PCLaw.Diary.Completed)
                    {
                        PCLaw.Diary.CompletionDate = int.Parse(Table.Rows[nCalendar]["CompletionDate"].ToString()); //always on time! (you can change this if required though)
                    }
                }//end if

                PCLaw.Diary.DiaryCodeID = PLDiaryCode.GetIDFromExtID1(Table.Rows[nCalendar]["DiaryCodeID"].ToString());

                PCLaw.Diary.MatterID = PLMatter.GetIDFromExtID1(Table.Rows[nCalendar]["MatterID"].ToString());
                if (PCLaw.Diary.MatterID == 0) //not found and is required....diary entry not added
                {
                    PCLaw.Diary.Clear();
                    continue;
                }

                //add lawyers to diary entry
                string[] lawyers = Table.Rows[nCalendar]["LawyerID"].ToString().Split('|');
                foreach (string lawyer in lawyers)
                {
                    nValue = PLLawyer.GetIDFromExtID1(lawyer);
                    if (nValue != 0)
                    {
                        PCLaw.Diary.AddLawyer(nValue);
                    }
                }//end foreach

                //add contacts to diary entry
                string[] contacts = Table.Rows[nCalendar]["ContactID"].ToString().Split('|');
                foreach (string contact in contacts)
                {
                    nValue = PLContact.GetIDFromExtID1(contact);
                    if (nValue != 0)
                    {
                        PCLaw.Diary.AddContact(nValue);
                    }
                }//end foreach

                nDate = int.Parse(Table.Rows[nCalendar]["ReminderDate"].ToString().Replace("-", ""));
                if (nDate < 19820101)
                {
                    PCLaw.Diary.ReminderDate = PCLaw.Diary.DueDate;
                }
                else
                {
                    PCLaw.Diary.ReminderDate = nDate;
                }

                PCLaw.Diary.MinutesToRemind = int.Parse(Table.Rows[nCalendar]["MinutesToRemind"].ToString());

                PCLaw.Diary.AddRecord();
            }//end for

            PCLaw.Diary.SendLast();
        }//end method